Skip to main content

SimulatorBase


csdl.core.simulator_base

_ReprClass Objects#

class _ReprClass(object)

Class for defining objects with a simple constant string repr.

This is useful for constants used in arg lists when you want them to appear in automatically generated source documentation as a certain string instead of python's default representation.

__init__#

def __init__(repr_string)

Inititialize the repr string.

Parameters

repr_string : str The string to be returned by repr

__repr__#

def __repr__()

Return our _repr_string.

Returns

str Whatever string we were initialized with.

SimulatorBase Objects#

class SimulatorBase()

A class that can be used as a base class for the Simulator class that a CSDL compiler back end would provide. This class is only here so that CSDL users and CSDL compiler back end developers have API documentation. CSDL users are not to use the SimulatorBase class provided by csdl, only the Simulator class provided by the CSDL compiler back end of choice.

__init__#

def __init__(model, reorder=False)

Constructor.

__getitem__#

def __getitem__(key) -> np.ndarray

Method to get variable values before or after a simulation run

__setitem__#

def __setitem__(key, val)

Method to set values for variables by name

run#

def run()

Method to run a simulation once. This method should be implemented so that it can be called repeatedly to solve an optimization problem.

compute_total_derivatives#

def compute_total_derivatives(return_format='array') -> Union[OrderedDict, np.ndarray]

Method to compute total derivatives (objective gradient and constraint jacobian)

Returns

Union[OrderedDict, np.ndarray]`

compute_exact_hessian#

def compute_exact_hessian()

Method to compute exact Hessian

check_partials#

def check_partials()

Method to compute the error for all partial derivatives of all operations within the model.

Returns

An object that is compatible with assert_check_partials

assert_check_partials#

def assert_check_partials(result, atol=1e-8, rtol=1e-8)

Method to check that the partial derivatives of all operations are within a specified tolerance.

Parameters

result: Return type of check_partials

visualize_implementation#

def visualize_implementation()

A method for the back end to provide its own visualization of the model.

get_design_variable_metadata#

def get_design_variable_metadata() -> dict

Method to get design variable metadata that an optimizer needs to define an optimization problem

Returns

`dict`

get_constraints_metadata#

def get_constraints_metadata() -> OrderedDict

Method to get constraint metadata that an optimizer needs to define an optimization problem

Returns

`OrderedDict`

update_design_variables#

def update_design_variables(x: np.ndarray, input_format='array')

Method for external optimizer to update design variable values

design_variables#

def design_variables(return_format='array') -> Union[OrderedDict, np.ndarray]

Method to provide optimizer with design variables Returns

`Union[OrderedDict, np.ndarray]`

objective#

def objective() -> float

Method to provide optimizer with objective

constraints#

def constraints(return_format='array') -> Union[OrderedDict, np.ndarray]

Method to provide optimizer with constraints

Returns

`Union[OrderedDict, np.ndarray]`

implicit_outputs#

def implicit_outputs()

Method to provide optimizer with implicit_outputs

residuals#

def residuals() -> Union[OrderedDict, np.ndarray]

Method to provide optimizer with residuals

objective_gradient#

def objective_gradient() -> Union[OrderedDict, np.ndarray]

Method to provide optimizer with total derivative of objective with respect to design variables; does not compute derivatives; must call Simulator.compute_total_derivatives to compute derivatives

Returns

`Union[OrderedDict, np.ndarray]`

constraint_jacobian#

def constraint_jacobian() -> Union[OrderedDict, np.ndarray]

Method to provide optimizer with total derivative of constraints with respect to design variables; does not compute derivatives; must call Simulator.compute_total_derivatives to compute derivatives

Returns

`Union[OrderedDict, np.ndarray]`

residuals_jacobian#

def residuals_jacobian() -> Union[OrderedDict, np.ndarray]

Method to provide optimizer with total derivatives of residuals with respect to design variables