### Install pyOptSparse with Testing Dependencies Source: https://context7.com/mdolab/pyoptsparse/llms.txt Installs pyOptSparse and its testing dependencies. Includes instructions to run tests. ```bash pip install .[testing] testflo . -v ``` -------------------------------- ### List Installed Optimizers Source: https://context7.com/mdolab/pyoptsparse/llms.txt Lists all optimizers successfully installed with pyOptSparse. Useful for verifying installation. ```python import pyoptsparse print(pyoptsparse.list_optimizers()) ``` -------------------------------- ### Install pyOptSparse from Source Source: https://context7.com/mdolab/pyoptsparse/llms.txt Builds and installs pyOptSparse from source using pip. Requires C and Fortran compilers on Linux. ```bash git clone https://github.com/mdolab/pyoptsparse.git cd pyoptsparse pip install . ``` -------------------------------- ### Install pyOptSparse with OptView Dependencies Source: https://github.com/mdolab/pyoptsparse/blob/main/doc/install.md Install pyOptSparse along with its optional dependencies required for OptView. This command should be run from the project root directory. ```bash pip install .[optview] ``` -------------------------------- ### List Installed Optimizers Source: https://github.com/mdolab/pyoptsparse/blob/main/doc/install.md Verifies the installed optimizers by running a Python command to import pyoptsparse and print the list of available optimizers. ```python import pyoptsparse; print(pyoptsparse.list_optimizers()) ``` -------------------------------- ### Install Documentation Build Dependencies Source: https://github.com/mdolab/pyoptsparse/blob/main/doc/contribute.md Install the necessary Python packages to build the project's documentation locally using Sphinx. This includes Sphinx itself, numpydoc, and themes. ```bash pip install sphinx numpydoc sphinx-rtd-theme sphinx_mdolab_theme ``` -------------------------------- ### Install pyOptSparse in Editable Mode Source: https://github.com/mdolab/pyoptsparse/blob/main/doc/contribute.md Use this command for an editable install of pyOptSparse, which is necessary due to the use of meson-python. Ensure build dependencies are installed first. ```bash pip install --no-build-isolation --editable . ``` -------------------------------- ### Install pyOptSparse with Pip Source: https://github.com/mdolab/pyoptsparse/blob/main/doc/install.md Installs pyOptSparse from a local clone of the repository using pip. Ensure the repository is cloned to a location not on your PYTHONPATH. ```bash pip install . ``` -------------------------------- ### Install pyOptSparse with Conda Source: https://github.com/mdolab/pyoptsparse/blob/main/doc/install.md Installs pyOptSparse and its default optimizers (including IPOPT) using conda-forge. For optimizers not packaged by conda, manual installation or building from source is required. ```bash conda install -c conda-forge pyoptsparse ``` -------------------------------- ### Install Testing Dependencies for pyOptSparse Source: https://github.com/mdolab/pyoptsparse/blob/main/doc/install.md Install the necessary dependencies to run the pyOptSparse unit and regression tests. This command should be run from the project root directory. ```bash pip install .[testing] ``` -------------------------------- ### Install dill for OptView Source: https://github.com/mdolab/pyoptsparse/blob/main/doc/postprocessing.md Install the 'dill' package using pip if you need to save an editable version of graphs generated in OptView. ```bash pip install dill ``` -------------------------------- ### User Install pyOptSparse with Pip Source: https://github.com/mdolab/pyoptsparse/blob/main/doc/install.md Performs a user-specific installation of pyOptSparse using pip, suitable for environments without virtual environments. ```bash pip install . --user ``` -------------------------------- ### Hot Start Optimization Source: https://github.com/mdolab/pyoptsparse/blob/main/doc/advancedFeatures.md Initiate an optimization using a previous history file to leverage accumulated information. This can significantly reduce computational time by avoiding the initial 'cold start' phase where optimizers rebuild approximations of the design space. Ensure the optimizer is deterministic and that settings affecting the optimization path remain consistent. ```python opt(optProb, hotStart = "previous_history_file.hst") ``` -------------------------------- ### Build and Install pyOptSparse Wheel (Linux/OSX) Source: https://github.com/mdolab/pyoptsparse/blob/main/doc/install.md Builds a wheel distribution of pyOptSparse and then installs it using pip. This command is executed after setting up the conda environment and assumes the 'dist' directory is present. ```bash # build wheel python -m build -n -x . # install wheel pip install --no-deps --no-index --find-links dist pyoptsparse ``` -------------------------------- ### Hot Start Source: https://context7.com/mdolab/pyoptsparse/llms.txt Hot start reads a previous history file, replays cached function evaluations, and continues from where the previous run stopped — preserving optimizer state for deterministic solvers. ```APIDOC ## Hot Start — Resume an Interrupted Optimization Hot start reads a previous history file, replays cached function evaluations, and continues from where the previous run stopped — preserving optimizer state for deterministic solvers. ```python from pyoptsparse import SLSQP, Optimization opt = SLSQP() # ... build optProb ... # First run: stop early after 10 iterations opt.setOption("MAXIT", 10) sol1 = opt(optProb, sens="FD", storeHistory="opt_hist.hst") # Second run: extend to 50 iterations, reuse cached evaluations opt.setOption("MAXIT", 50) sol2 = opt(optProb, sens="FD", hotStart="opt_hist.hst", storeHistory="opt_hist.hst") print(sol2.fStar) # Previously-evaluated points are read from history; only new points call objfunc ``` ``` -------------------------------- ### Install isort for Import Sorting Source: https://github.com/mdolab/pyoptsparse/blob/main/doc/contribute.md Install the 'isort' package to manage import sorting. This is a required step for code formatting checks. ```bash pip install isort ``` -------------------------------- ### Print Optimization Problem Source: https://github.com/mdolab/pyoptsparse/blob/main/doc/quickstart.md Print the optimization problem object to verify its setup. ```python # Check optimization problem print(optProb) ``` -------------------------------- ### Specify Compilers for Pip Install Source: https://github.com/mdolab/pyoptsparse/blob/main/doc/install.md Installs pyOptSparse using pip while specifying non-default compilers (e.g., Intel compilers) via environment variables FC and CC. This is useful when custom compiler paths are needed. ```bash FC=$(which ifort) CC=$(which icc) pip install . ``` -------------------------------- ### pyoptsparse.pyOpt_optimizer.list_optimizers Source: https://github.com/mdolab/pyoptsparse/blob/main/doc/api/optimizer.md Lists all optimizers that have been successfully installed and are available for use within the PyOptSparse library. ```APIDOC ## pyoptsparse.pyOpt_optimizer.list_optimizers() ### Description List all optimizers which were installed successfully and available for use. ``` -------------------------------- ### History File Structure Example Source: https://github.com/mdolab/pyoptsparse/blob/main/doc/api/history.md This illustrates the typical directory and file layout of a pyOptSparse history file, showing metadata, variable/constraint/objective information, and iteration data. ```text ├── metadata │ ├── optName │ ├── optOptions │ ├── nprocs │ ├── startTime │ ├── endTime │ ├── optTime │ ├── optimizer │ ├── version │ └── optVersion ├── optProb ├── varInfo │ └── xvars │ ├── lower │ ├── upper │ └── scale ├── conInfo │ └── con │ ├── lower │ ├── upper │ └── scale ├── objInfo │ └── obj │ └── scale ├── 0 │ ├── xuser │ │ └── xvars │ ├── funcs │ │ ├── obj │ │ └── con │ ├── iter │ ├── fail │ ├── isMajor | └── time ├── 1 │ ├── xuser │ │ └── xvars │ ├── funcsSens │ │ ├── obj │ │ │ └── xvars │ │ └── con │ │ └── xvars │ ├── iter │ ├── fail │ ├── isMajor | └── time └── last ``` -------------------------------- ### Dynamically Select Optimizer in pyOptSparse Source: https://context7.com/mdolab/pyoptsparse/llms.txt Selects an optimizer (IPOPT or SLSQP) based on its availability. Ensure the desired optimizer is installed and accessible. ```python from pyoptsparse import OPT opt_name = "IPOPT" if "IPOPT" in available else "SLSQP" opt = OPT(opt_name, options={}) ``` -------------------------------- ### list_optimizers Source: https://context7.com/mdolab/pyoptsparse/llms.txt Returns a list of successfully installed and importable optimizers available in pyOptSparse. ```APIDOC ## `list_optimizers` — Check Available Optimizers `list_optimizers()` returns a list of successfully installed and importable optimizers. ```python import pyoptsparse available = pyoptsparse.list_optimizers() print(available) # ['ALPSO', 'CONMIN', 'IPOPT', 'NSGA2', 'PSQP', 'SLSQP'] ``` ``` -------------------------------- ### List Available Optimizers with list_optimizers Source: https://context7.com/mdolab/pyoptsparse/llms.txt The `list_optimizers()` function returns a list of all optimizers that are successfully installed and importable within the pyOptSparse environment. ```python import pyoptsparse available = pyoptsparse.list_optimizers() print(available) # ['ALPSO', 'CONMIN', 'IPOPT', 'NSGA2', 'PSQP', 'SLSQP'] ``` -------------------------------- ### setDVsFromHistory(histFile, key=None) Source: https://github.com/mdolab/pyoptsparse/blob/main/doc/api/optimization.md Sets optimization variables from a previous optimization, allowing for cold starts even if variables have been added or removed. ```APIDOC ## setDVsFromHistory(histFile, key=None) ### Description Set optimization variables from a previous optimization. This is like a cold start, but some variables may have been added or removed from the previous optimization. This will try to set all variables it can. ### Parameters #### Request Body - **histFile** (str) - Required - Filename of the history file to read - **key** (str, optional) - Key of the history file to use for the x values. The default is None which will use the last x-value stored in the dictionary. ``` -------------------------------- ### Run pyOptSparse Tests Source: https://github.com/mdolab/pyoptsparse/blob/main/doc/install.md Execute all pyOptSparse unit and regression tests. Ensure testing dependencies are installed first. This command is run from the project root directory. ```bash testflo . -v ``` -------------------------------- ### Format Imports with isort Source: https://github.com/mdolab/pyoptsparse/blob/main/doc/contribute.md Run 'isort' on the current directory to automatically sort all import statements according to the project's style guide. This is a mandatory check for pull requests. ```bash isort . ``` -------------------------------- ### Initialize DVs from History using setDVsFromHistory Source: https://context7.com/mdolab/pyoptsparse/llms.txt Initializes design variables for an optimization problem from a specified history file. This allows for cold starts using previous solutions without replaying the entire history. You can optionally specify a particular call counter. ```python from pyoptsparse import Optimization, SLSQP optProb = Optimization("problem", objfunc) optProb.addVarGroup("xvars", 4, lower=1, upper=5, value=[1, 5, 5, 1]) optProb.addObj("obj") # Set initial DVs from the last entry of a previous history file optProb.setDVsFromHistory("previous_opt.hst") # Optionally specify a particular call counter optProb.setDVsFromHistory("previous_opt.hst", key="42") opt = SLSQP() sol = opt(optProb, sens="FD") ``` -------------------------------- ### Hot Start Optimization from History File Source: https://context7.com/mdolab/pyoptsparse/llms.txt Resumes an interrupted optimization run by reading a previous history file, replaying cached evaluations, and preserving optimizer state. This allows continuing from a specific iteration. ```python from pyoptsparse import SLSQP, Optimization opt = SLSQP() # ... build optProb ... # First run: stop early after 10 iterations opt.setOption("MAXIT", 10) sol1 = opt(optProb, sens="FD", storeHistory="opt_hist.hst") # Second run: extend to 50 iterations, reuse cached evaluations opt.setOption("MAXIT", 50) sol2 = opt(optProb, sens="FD", hotStart="opt_hist.hst", storeHistory="opt_hist.hst") print(sol2.fStar) # Previously-evaluated points are read from history; only new points call objfunc ``` -------------------------------- ### printSparsity Source: https://github.com/mdolab/pyoptsparse/blob/main/doc/api/optimization.md Prints an ASCII visualization of the Jacobian sparsity structure to help users verify the optimization problem setup. It is recommended to call this before starting an optimization. ```APIDOC ## printSparsity(verticalPrint=False) ### Description Prints an (ASCII) visualization of the Jacobian sparsity structure. This helps the user visualize what pyOptSparse has been given and helps ensure it is what the user expected. It is highly recommended this function be called before the start of every optimization to verify the optimization problem setup. ### Parameters #### Parameters - **verticalPrint** (bool) - Optional - True if the design variable names in the header should be printed vertically instead of horizontally. If true, this will make the constraint Jacobian print out more narrow and taller. ### Warnings This function is **collective** on the optProb comm. It is therefore necessary to call this function on **all** processors of the optProb comm. ``` -------------------------------- ### Configure and Initialize Optimizer Source: https://github.com/mdolab/pyoptsparse/blob/main/doc/quickstart.md Set up the optimizer options and initialize the chosen optimizer (SLSQP in this case). ```python # Optimizer optOptions = {"IPRINT": -1} opt = SLSQP(options=optOptions) ``` -------------------------------- ### Run OptView-Dash Source: https://github.com/mdolab/pyoptsparse/blob/main/doc/postprocessing.md Launches the OptView-Dash application. Open the provided server URL in your browser to view the application. This command can also accept multiple history files. ```bash optview_dash ``` -------------------------------- ### Run OptView with a history file Source: https://github.com/mdolab/pyoptsparse/blob/main/doc/postprocessing.md Launch OptView from the terminal to visualize optimization histories. Specify the history file name; defaults to 'opt_hist.hst' if not provided. ```bash optview histFile ``` -------------------------------- ### Set up Optimization Problem in Python Source: https://github.com/mdolab/pyoptsparse/blob/main/paper/paper.md Initializes the Optimization object and adds design variable groups, nonlinear constraints, a linear constraint, and the objective function. Specifies Jacobian sparsity using the 'wrt' argument. ```python # Optimization Object optProb = Optimization("Example Optimization", objfunc) # Design Variables nx = 2 lower = [-10, -10] upper = [10, 100] value = [-5, 6] optProb.addVarGroup("x", nx, lower=lower, upper=upper, value=value) ny = 4 optProb.addVarGroup("y", ny, lower=-10, upper=None, value=0) # Nonlinear constraints ncons = 2 lower = [-10, -10] upper = [None, 10] optProb.addConGroup("con", ncons, wrt="x", lower=lower, upper=upper) # Linear constraint jac = np.zeros((1, ny)) jac[0, 0] = 1 jac[0, 1] = -2 optProb.addConGroup( "lin_con", 1, lower=5, upper=5, wrt="y", jac={"y": jac}, linear=True ) # Objective optProb.addObj("obj") ``` -------------------------------- ### Initialize SLSQP Optimizer Source: https://github.com/mdolab/pyoptsparse/blob/main/doc/quickstart.md Initializes the SLSQP optimizer with specific options. Use this to configure solver parameters before optimization. ```python # Optimizer optOptions = {"IPRINT": -1} opt = SLSQP(options=optOptions) ``` -------------------------------- ### Run OptView and save figures Source: https://github.com/mdolab/pyoptsparse/blob/main/doc/postprocessing.md Execute OptView and specify an output directory to save generated figures. If not specified, figures are saved in the current directory. ```bash optview histFile --output ~/my_figures ``` -------------------------------- ### SNOPT Callback Function Example Source: https://github.com/mdolab/pyoptsparse/blob/main/doc/optimizers/SNOPT.md Example of a callback function that can be supplied to SNOPT to be called at the end of each major iteration. This function saves the restart dictionary to a file. ```python def snstopCallback(iterDict, restartDict): # Get the major iteration number nMajor = iterDict["nMajor"] # Save the restart dictionary writePickle(f"restart_{nMajor}.pickle", restartDict) return 0 ``` -------------------------------- ### Instantiate Optimizer Using OPT Convenience Function Source: https://github.com/mdolab/pyoptsparse/blob/main/doc/guide.md Use the `OPT` convenience function to instantiate an optimizer by its string name, allowing for easy switching between optimizers without explicit imports. ```python from pyoptsparse import OPT opt = OPT("SLSQP", options=options) ``` -------------------------------- ### Call Optimizer with Different Gradient Sensitivities Source: https://context7.com/mdolab/pyoptsparse/llms.txt Demonstrates calling the optimizer with different sensitivity analysis methods: Finite Difference (FD), Central Difference (CD), Complex Step (CS), and user-supplied analytic gradients. ```python from pyoptsparse import OPT, Optimization import numpy as np def objfunc(xdict): x = xdict["xvars"] funcs = {"obj": x[0] * x[3] * (x[0]+x[1]+x[2]) + x[2], "con1": x[0]*x[1]*x[2]*x[3], "con2": x[0]**2+x[1]**2+x[2]**2+x[3]**2} return funcs, False def sens(xdict, funcs): x = xdict["xvars"] funcsSens = { "obj": {"xvars": np.array([x[0]*x[3]+x[3]*(x[0]+x[1]+x[2]), x[0]*x[3], x[0]*x[3]+1.0, x[0]*(x[0]+x[1]+x[2])])}, "con1": {"xvars": [[x[1]*x[2]*x[3], x[0]*x[2]*x[3], x[0]*x[1]*x[3], x[0]*x[1]*x[2]]}}, "con2": {"xvars": [[2*x[0], 2*x[1], 2*x[2], 2*x[3]]]}, } return funcsSens, False optProb = Optimization("HS071", objfunc) optProb.addVarGroup("xvars", 4, lower=1, upper=5, value=[1, 5, 5, 1]) optProb.addCon("con1", lower=25) optProb.addCon("con2", lower=40, upper=40) optProb.addObj("obj") opt = OPT("SLSQP") # Finite difference gradients (forward) sol = opt(optProb, sens="FD") # Central difference sol = opt(optProb, sens="CD") # Complex step (more accurate than FD/CD) sol = opt(optProb, sens="CS") # Analytic user-supplied gradients sol = opt(optProb, sens=sens) print(sol) # Optimization Problem -- HS071 Constraint Problem # Solution: # Total Time: 0.0062 # Calls to Objective Function: 22 # Objectives: obj = 1.70140E+01 ``` -------------------------------- ### Initialize ParOpt Optimizer with Sparse Disabled Source: https://github.com/mdolab/pyoptsparse/blob/main/doc/optimizers/ParOpt.md Instantiate the ParOpt optimizer using pyOptSparse's OPT method. Set `sparse=False` when using ParOpt's trust-region algorithm, as it requires dense storage for the constraint Jacobian. ```python from pyoptsparse import OPT opt = OPT("ParOpt", sparse=False) ``` -------------------------------- ### Get Constraint Names Source: https://github.com/mdolab/pyoptsparse/blob/main/doc/api/history.md Returns a list of all constraint names stored in the history file. ```python history.getConNames() ``` -------------------------------- ### Get Optimization Problem Object Source: https://github.com/mdolab/pyoptsparse/blob/main/doc/api/history.md Returns a copy of the optProb object associated with the optimization history. ```python history.getOptProb() ``` -------------------------------- ### Uninstall pyOptSparse Source: https://github.com/mdolab/pyoptsparse/blob/main/doc/install.md Remove the pyOptSparse package from your environment. This command can be used for clean installations or to uninstall the library. ```bash pip uninstall pyoptsparse ``` -------------------------------- ### Access Solution Object Properties Source: https://context7.com/mdolab/pyoptsparse/llms.txt Demonstrates how to access key results from the Solution object after an optimization run, including optimal variables, objective values, Lagrange multipliers, and performance information. ```python from pyoptsparse import SLSQP, Optimization # ... build optProb and solve ... sol = opt(optProb, sens="FD") # Print full summary table print(sol) # Access optimal objective value (scalar or dict for multi-objective) print(sol.fStar) # e.g. -3456.0 # Access optimal design variable dict print(sol.xStar) # {'xvars': array([24., 12., 12.])} # Access Lagrange multipliers print(sol.lambdaStar) # Optimizer exit inform code and message print(sol.optInform) # Timing and call counters print(sol.info) # {'Time': 0.006, 'calls': {'obj': 22, 'sens': 8}, ...} ``` -------------------------------- ### Get Design Variable Names Source: https://github.com/mdolab/pyoptsparse/blob/main/doc/api/history.md Returns a list of all design variable names stored in the history file. ```python history.getDVNames() ``` -------------------------------- ### Get Metadata Source: https://github.com/mdolab/pyoptsparse/blob/main/doc/api/history.md Returns a copy of the metadata stored in the history file, such as optimizer name, options, and timing information. ```python history.getMetadata() ``` -------------------------------- ### Instantiate Optimizer Directly Source: https://github.com/mdolab/pyoptsparse/blob/main/doc/guide.md Import and instantiate a specific optimizer class directly, passing any necessary options. ```python from pyoptsparse import SLSQP opt = SLSQP(options=options) ``` -------------------------------- ### Run OptView with multiple history files Source: https://github.com/mdolab/pyoptsparse/blob/main/doc/postprocessing.md Open multiple history files in a single OptView instance. Suffixes '_A', '_B', etc., are appended to variable/function names to distinguish files. ```bash optview histFile1 histFile2 histFile3 ``` -------------------------------- ### Get Objective Names Source: https://github.com/mdolab/pyoptsparse/blob/main/doc/api/history.md Returns a list of all objective names stored in the history file. This follows the same structure as ConNames and DVNames. ```python history.getObjNames() ``` -------------------------------- ### Initialize Optimization Problem Source: https://github.com/mdolab/pyoptsparse/blob/main/doc/guide.md Create an Optimization object to define the problem name and the objective/constraint function. ```python from pyoptsparse import Optimization optProb = Optimization("name", objconFun) ``` -------------------------------- ### Get Objective Information Source: https://github.com/mdolab/pyoptsparse/blob/main/doc/api/history.md Retrieves ObjInfo for all objectives by default, or for a specific objective if a key is provided. This follows the same structure as ConInfo and DVInfo. ```python history.getObjInfo(key='obj') ``` ```python history.getObjInfo() ``` -------------------------------- ### Get Iteration Keys Source: https://github.com/mdolab/pyoptsparse/blob/main/doc/api/history.md Returns a list of keys available at each optimization iteration. This is useful for inspecting what information is saved per iteration. ```python history.getIterKeys() ``` -------------------------------- ### Get Call Counters Source: https://github.com/mdolab/pyoptsparse/blob/main/doc/api/history.md Retrieves a list of all call counters stored in the history file. Each entry represents a distinct optimization call. ```python history.getCallCounters() ``` -------------------------------- ### Print Solution Source: https://github.com/mdolab/pyoptsparse/blob/main/doc/quickstart.md Print the solution object to view the results of the optimization. ```python # Check Solution print(sol) ``` -------------------------------- ### Add Constraints with addCon and addConGroup Source: https://context7.com/mdolab/pyoptsparse/llms.txt Demonstrates adding inequality, equality, grouped, scaled, and sparse constraints using `addCon` and `addConGroup`. Use `wrt` to specify sparsity for constraints. ```python from pyoptsparse import Optimization optProb = Optimization("HS071", objfunc) optProb.addVarGroup("xvars", 4, lower=1, upper=5, value=[1, 5, 5, 1]) # Inequality: con1 >= 25 (no upper bound) optProb.addCon("con1", lower=25) # Equality: con2 == 40 optProb.addCon("con2", lower=40, upper=40) # Group of 2 inequality constraints (upper=0) optProb.addConGroup("con", 2, lower=None, upper=0.0) # Scaled constraint (optimizer sees value/10000, bound also /10000 internally) optProb.addCon("stress", upper=10000, scale=1.0 / 10000) # Sparse: constraint depends only on 'x' and 'z' DVs (not 'y') optProb.addCon("con3", lower=4, wrt=["x", "z"]) ``` -------------------------------- ### Clean Build Directory Source: https://github.com/mdolab/pyoptsparse/blob/main/doc/contribute.md After an editable install, clean the build directory before subsequent builds to avoid issues. This command removes the 'build' directory. ```bash rm -rf build ``` -------------------------------- ### Solve Optimization Problem with SLSQP in Python Source: https://github.com/mdolab/pyoptsparse/blob/main/paper/paper.md Instantiates the SLSQP optimizer and calls it to solve the defined optimization problem. Prints the solution object. ```python # Optimizer opt = OPT("SLSQP", options={}) # Optimize sol = opt(optProb, sens="CS") print(sol) ``` -------------------------------- ### setDVsFromHistory Source: https://context7.com/mdolab/pyoptsparse/llms.txt Initialize design variables from a completed history file without replaying the full history. This is useful for cold starts from previous solutions. ```APIDOC ## `setDVsFromHistory` — Cold Start from Previous Solution Initialize design variables from a completed history file without replaying the full history (unlike hot start). ```python from pyoptsparse import Optimization, SLSQP optProb = Optimization("problem", objfunc) optProb.addVarGroup("xvars", 4, lower=1, upper=5, value=[1, 5, 5, 1]) optProb.addObj("obj") # Set initial DVs from the last entry of a previous history file optProb.setDVsFromHistory("previous_opt.hst") # Optionally specify a particular call counter optProb.setDVsFromHistory("previous_opt.hst", key="42") opt = SLSQP() sol = opt(optProb, sens="FD") ``` ``` -------------------------------- ### Get Extra Functions Names Source: https://github.com/mdolab/pyoptsparse/blob/main/doc/api/history.md Returns the names of extra key:value pairs stored in the `funcs` dictionary for each iteration, which are not used by the optimizer. ```python history.getExtraFuncsNames() ``` -------------------------------- ### Runtime Option Management with setOption/getOption Source: https://context7.com/mdolab/pyoptsparse/llms.txt Optimizer options can be set at construction time or updated between runs using `setOption`/`getOption`. This allows dynamic modification of optimizer behavior. ```python from pyoptsparse import SLSQP opt = SLSQP(options={"MAXIT": 50}) # Modify option after construction opt.setOption("MAXIT", 100) opt.setOption("ACC", 1e-9) # Retrieve current option value maxit = opt.getOption("MAXIT") print(maxit) # 100 # Get optimizer exit inform code after a run print(opt.getInform()) ``` -------------------------------- ### IPOPT Optimizer Class Initialization Source: https://github.com/mdolab/pyoptsparse/blob/main/doc/optimizers/IPOPT.md Initializes the IPOPT optimizer. This class inherits from the Optimizer Abstract Class. ```APIDOC ## class pyoptsparse.pyIPOPT.pyIPOPT.IPOPT(*args, **kwargs) IPOPT Optimizer Class - Inherited from Optimizer Abstract Class IPOPT Optimizer Class Initialization ``` -------------------------------- ### Create and Activate Conda Environment for pyOptSparse Build (Linux/OSX) Source: https://github.com/mdolab/pyoptsparse/blob/main/doc/install.md Sets up a new conda environment named 'pyos-build', activates it, configures conda-forge as the primary channel, and updates the environment using the provided 'environment.yml' file. This is the first step for building pyOptSparse with conda on Linux or macOS. ```bash conda create -y -n pyos-build conda activate pyos-build conda config --env --add channels conda-forge conda config --env --set channel_priority strict conda env update -f .github/environment.yml ``` -------------------------------- ### Structure for Analytic Derivative Dictionary Source: https://github.com/mdolab/pyoptsparse/blob/main/doc/guide.md This example shows the expected nested dictionary structure for returning analytic derivatives, mapping objectives and constraints to design variables. ```python {"obj": {"xvars": [1, 2, 3]}, "con": {"xvars": [[4, 5, 6], [7, 8, 9]]}} ```