Skip to content

Blog

配置使用 ChatGPT Academic

离线安装包

你可以到 GitHub Release 页面下载 ChatGPT Academic 的离线安装包,解压后安装即可使用。

使用 Python 安装

首先,你需要安装 Python,可以从 Python 官网 下载 Python 3.8 - 3.11 安装包(Python 3.12 暂不支持)。 安装时注意勾选 Add Python to PATH 选项将 Python 安装路径添加到环境变量 PATH 中。 安装完成后,打开命令行窗口 cmd,输入 python --version,如果显示 Python 版本号,则说明安装成功。使用以下命令安装 chatgpt-academic

python -m pip install chatgpt-academic

配置环境变量

安装完成后,使用环境变量配置 ChatGPT Academic 项目,具体可查阅 gpt-academic 项目文档。 例如,配置 gpt-3.5-turboOpenAI 模型时,设置名为 API_KEY 的环境变量,值为 OpenAI 的 API 密钥,如:

sk-123456789xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx123456789

若需使用第三方代理服务提供的 OpenAI 模型,还需配置 API_URL_REDIRECT 环境变量,如:

{"https://api.openai.com/v1/chat/completions": "https://reverse-proxy-url/v1/chat/completions"}

配置完成后,在命令行窗口输入 chatgpt-academicgpta 命令,即可启动 ChatGPT Academic 项目。 chatgpt-academic.exegpta.exe 可执行文件位于 Python 安装目录下的 Scripts 文件夹中,如:

C:\Users\{username}\AppData\Local\Programs\Python\Python311\Scripts

{username} 为当前用户名,Python311 为 Python 版本号。你可以为 chatgpt-academicgpta 命令创建快捷方式,方便启动项目。

Freezing Installed Python Packages

Use the pip freeze command to generate a list of installed packages and their versions and save it to the requirements.txt file.

pip freeze > requirements.txt

The requirements.txt file can be used to install the same packages and versions on another machine.

pip install -r requirements.txt

Frequently Used Softwares

Some frequently used softwares for my daily work.

Drawing

IDEs and Code Editors

Programming Language and Frameworks

Version Control

Matplotlib Widget for PyQt

The following snippet is a MplWidget class that can be used in PyQt or PySide applications. It is a QWidget that contains a matplotlib figure and a toolbar.

import matplotlib.pyplot as plt
from matplotlib.backends.backend_qtagg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qtagg import NavigationToolbar2QT as NavigationToolbar
from matplotlib.figure import Figure
from qtpy import QtWidgets

class MplWidget(QtWidgets.QWidget):
    """A PyQt/Pyside widget that contains a matplotlib figure"""

    #: Matplotlib figure
    figure: Figure
    #: Figure canvas
    canvas: FigureCanvas

    def __init__(self, figure: Figure = None, toolbar: bool = True, parent=None, *args, **kwargs):
        """Create a new Matplotlib widget

        Parameters
        ----------
        figure : matplotlib.figure.Figure, optional
            Figure to use, by default None
        toolbar : bool, optional
            Whether to show the toolbar, by default True
        parent : QtWidgets.QWidget, optional
            Parent widget, by default None
        args, kwargs
            Additional arguments passed to the QWidget constructor
        """
        super().__init__(parent, *args, **kwargs)

        # Figure elements
        self.figure = figure or plt.figure()
        self.canvas = FigureCanvas(self.figure)
        self.canvas.setParent(self)
        self.toolbar = NavigationToolbar(self.canvas, self) if toolbar else None

        # Layout
        self.layout = QtWidgets.QVBoxLayout(self)
        self.layout.setContentsMargins(0, 0, 0, 0)
        self.layout.addWidget(self.toolbar)
        self.layout.addWidget(self.canvas)

    def draw(self):
        """Redraw the figure"""
        self.canvas.draw()

Debug Abaqus Subroutines

Enable debugging feature in Abaqus

Go the the Abaqus configuration file abaqus_v6.env or win86_64.env in the Abaqus path, for me, it locates in the following path:

C:\SIMULIA\EstProducts\2021\win_b64\SMA\site

The file is like this:

#-*- mode: python -*-

#############################################################################
#                                                                           #
#     Compile and Link commands for ABAQUS on the Windows 64 Platform       #
#                                                                           #
#############################################################################

# import os # <-- Debugging
# os.environ['GLOBAL_ENABLE_FPE'] = 'TRUE' # <-- Debugging

# Location of the /include directory in the ABAQUS installation
abaHomeInc = os.path.abspath(os.path.join(os.environ.get('ABA_HOME', ''), os.pardir))

compile_cpp=['cl', '/c', '/W0', '/MD', '/TP',
             '/EHsc', '/DNDEBUG', '/DWIN32', '/DTP_IP', '/D_CONSOLE',
             '/DNTI', '/DFLT_LIC', '/DOL_DOC', '/D__LIB__', '/DHKS_NT',
             '/D_WINDOWS_SOURCE', '/DFAR=', '/D_WINDOWS', '/DABQ_WIN86_64', '%P',
             # '/O1', # <-- Optimization
             # '/Zi', # <-- Debug symbols
             '/I%I', '/I'+abaHomeInc]

compile_fmu=['win64CmpWrp', '-m64', '-msvc9', 'cl', '/LD',
             '/D_WINDOWS', '/TC', '/W0',  '/I%I', '/I'+abaHomeInc]

## Fortran compile command for User Subroutines

compile_fortran=['ifort',
                 '/c', '/fpp', '/extend-source',
                 '/DABQ_WIN86_64',  '/DABQ_FORTRAN',
                 '/iface:cref', '/recursive',
                 '/Qauto',  # <-- important for thread-safety of parallel user subroutines
                 '/align:array64byte',
                 '/Qpc64',                    # set FPU precision to 53 bit significand
                 '/Qprec-div', '/Qprec-sqrt', # improve precision of FP divides and sqrt
                 '/Qfma-',                    # disable floating point fused multiply-add
                 '/fp:precise',               # floating point model: precise
                 '/Qimf-arch-consistency:true', # math library consistent results
                 '/Qfp-speculation:safe',     # floating point speculations only when safe
                 '/Qprotect-parens',          # honor parenthesis during expression evaluation
                 '/Qfp-stack-check',          # enable stack overflow protection checks
                 '/reentrancy:threaded',      # important for thread-safety
                 #'/Qinit=zero','/Qinit=arrays',  # automatically initialize all arrays to zero
                 #'/Qinit=snan', '/Qinit=arrays', # automatically initialize all arrays to SNAN
                 '/QxSSE3', '/QaxAVX',        # generate SSE3, SSE2, and SSE instructions
                 # '/Od', '/Ob0',  # <-- Disable Optimization for Debugging
                 # '/Zi',          # <-- Debugging Information
                 '/include:%I', '/include:'+abaHomeInc, '%P']

link_sl=['LINK',
         '/nologo', '/NOENTRY', '/INCREMENTAL:NO', '/subsystem:console', '/machine:AMD64',
         '/NODEFAULTLIB:LIBC.LIB', '/NODEFAULTLIB:LIBCMT.LIB',
         '/DEFAULTLIB:OLDNAMES.LIB', '/DEFAULTLIB:LIBIFCOREMD.LIB', '/DEFAULTLIB:LIBIFPORTMD.LIB', '/DEFAULTLIB:LIBMMD.LIB',
         '/DEFAULTLIB:kernel32.lib', '/DEFAULTLIB:user32.lib', '/DEFAULTLIB:advapi32.lib',
         '/FIXED:NO', '/dll',
         # '/debug', # <-- Debugging
         '/def:%E', '/out:%U', '%F', '%A', '%L', '%B',
         'oldnames.lib', 'user32.lib', 'ws2_32.lib', 'netapi32.lib',
         'advapi32.lib', 'msvcrt.lib', 'vcruntime.lib', 'ucrt.lib']

link_exe=['LINK',
          '/nologo', '/INCREMENTAL:NO', '/subsystem:console', '/machine:AMD64', '/STACK:20000000',
          '/NODEFAULTLIB:LIBC.LIB', '/NODEFAULTLIB:LIBCMT.LIB', '/DEFAULTLIB:OLDNAMES.LIB', '/DEFAULTLIB:LIBIFCOREMD.LIB',
          '/DEFAULTLIB:LIBIFPORTMD.LIB', '/DEFAULTLIB:LIBMMD.LIB', '/DEFAULTLIB:kernel32.lib',
          '/DEFAULTLIB:user32.lib', '/DEFAULTLIB:advapi32.lib',
          '/FIXED:NO', '/LARGEADDRESSAWARE',
          # '/debug', # <-- Debugging
          '/out:%J', '%F', '%M', '%L', '%B', '%O',
          'oldnames.lib', 'user32.lib', 'ws2_32.lib', 'netapi32.lib',
          'advapi32.lib', 'msvcrt.lib', 'vcruntime.lib', 'ucrt.lib']

## Link command to be used for ABAQUS/MAKE on machines without the Fortran compiler.
## Uncomment it to enable.
#
#link_exe=['LINK', '/nologo', '/INCREMENTAL:NO', '/subsystem:console', '/machine:AMD64', '/NODEFAULTLIB:LIBC.LIB', '/NODEFAULTLIB:LIBCMT.LIB',
#          '/DEFAULTLIB:OLDNAMES.LIB', '/DEFAULTLIB:MSVCRT.LIB', '/DEFAULTLIB:kernel32.lib', '/DEFAULTLIB:user32.lib', '/DEFAULTLIB:advapi32.lib',
#          '/FIXED:NO', '/LARGEADDRESSAWARE', '/out:%J', '%F', '%M', '%L', '%B', '%O',
#         'oldnames.lib', 'user32.lib', 'ws2_32.lib', 'netapi32.lib',
#         'advapi32.lib', 'msvcrt.lib', 'vcruntime.lib', 'ucrt.lib']

# Remove the temporary names from the namespace
del abaHomeInc

Uncomment all the lines that end with comment of Debugging.

Insert some extra codes to pause in your subroutine when running Abaqus

Add some codes like this to pause at the subroutine after the declaration of variables, like this:

!-------------------------- FOR DEBUGGING ------------------------------------
LOGICAL :: FIRSTRUN = .TRUE.
INTEGER TEMPVAR
IF (FIRSTRUN == .TRUE.) THEN
    WRITE(*, *) 'PLEASE INPUT A VALUE:'
    READ(*, *) TEMPVAR
    FIRSTRUN = .FALSE.
END IF
TEMPVAR = 1234

Run Abaqus command to submit the job

Use the Abaqus command to submit the job, like this

abaqus job=Job-1 user=FRIC_coulomb int

If you have added some code to pause in the subroutine, the program will stop in the command window, like this

10/30/2021 11:51:14 PM
Begin Analysis Input File Processor
10/30/2021 11:51:14 PM
Run pre.exe
10/30/2021 11:51:17 PM
End Analysis Input File Processor
Begin Abaqus/Standard Analysis
10/30/2021 11:51:17 PM
Run standard.exe
PLEASE INPUT A VALUE:

Attach to process in Visual Studio

Open your subroutine file in Visual Studio, click Debug -> Attach to Process, choose the Abaqus program standard.exe or explicit_dp.exe.

Resume running the subroutine and debug in Visual Studio

Add a breakpoint in the subroutine file in Visual Studio, resume running the subroutine in the command window, i.e., input the temporary value, the subroutine will stop in Visual Studio, and now you can debug your subroutine in Visual Studio!

Warning

Abaqus CAE cannot be opened if the debug mode is activated, change the configuration file to the old version and you can open Abqus CAE again.