engforge.problem_context.ProblemExec
- class ProblemExec(system, kw_dict=None, Xnew=None, ctx_fail_new=False, **opts)[source]
Bases:
objectRepresents the execution context for a problem in the system. The ProblemExec class provides a uniform set of options for managing the state of the system and its solvables, establishing the selection of combos or de/active attributes to Solvables. Once once created any further entracnces to ProblemExec will return the same instance until finally the last exit is called.
## params: - _problem_id: uuid for subproblems, or True for top level, None means uninitialized
Initializes the ProblemExec.
#TODO: exit system should abide by update / signals options
#TODO: provide data storage options for dataframe / table storage history/ record keeping (ss vs transient data)
#TODO: create an option to copy the system and run operations on it, and options for applying the state from the optimized copy to the original system
- Parameters:
system – The system to be executed.
Xnew – The new state of the system to set at the start o the problem context, and will revert after the problem exits, optional
ctx_fail_new – Whether to raise an error if no execution context is available, use in utility methods ect. Default is False.
kw_dict – A keyword argument dictionary to be parsed for solver options, and removed from the outer context. Changes are made to this dictionary, so they are removed automatically from the outer context, and thus no longer passed to interior vars.
dxdt – The dynamics integration method. Default is None meaning that dynamic vars are not considered for minimization unless otherwise specified. Steady State can be specified by dxdt=0 all dynamic vars are considered as solver variables, with the constraint that their rate of change is zero. If a dictionary is passed then the dynamic vars are considered as solver variables, with the constraint that their rate of change is equal to the value in the dictionary, and all other unspecified rates are zero (steady).
#### Solver Selection Options :param combos: The selection of combos. Default is ‘*’ (select all). :param ign_combos: The combos to be ignored. :param only_combos: The combos to be selected. :param add_obj: Whether to add an objective to the solver. Default is True. :param slv_vars: The selection of solvables. Default is ‘*’ (select all). :param add_vars: The solvables to be added to the solver. :param ign_vars: The solvables to be ignored. :param only_vars: The solvables to be selected. :param only_active: Whether to select only active items. Default is True. :param activate: The solvables to be activated. :param deactivate: The solvables to be deactivated. :param fail_revert: Whether to raise an error if no solvables are selected. Default is True. :param revert_last: Whether to revert the last change. Default is True. :param revert_every: Whether to revert every change. Default is True. :param exit_on_failure: Whether to exit on failure, or continue on. Default is True.
Methods
activate_temp_stateapplies all post signals
applies all pre signals
use this function to change the value of a system var and update the start state, multiple uses in the same context will not change the record preserving the start value
clean_contextchecks if the cache has a session
criticaldebugdebug the levels of the context
discard all contexts
errorhandles the error action wrt to the problem
caches the system references, and parses the system arguments
handles the exit action wrt system
exit_and_revertexit_to_levelexit_with_stateselects only settable refs
a more time consuming but throughout refresh of the system
extracts the combo input from the kwargs
returns the parent key of the key
returns the values of the refs
get the session
handle_solutioninfoprovides the dynamic rate of the system at time t, and state x
integratewhat things need to be refreshed per execution, this is important whenever items are replaced
msgsplits strings or lists and returns a list of options for the key, if nothing found returns None if fail set to True raises an exception, otherwise returns the default value
convert all contexts to a new storage format
converts an objective to a positive value
Updates the post/both signals after the solver has been executed.
updates the system
Updates the pre/both signals after the solver has been executed.
Print all the information of each component's dictionary.
refresh the system references
reset all contexts to a new storage format
reset the data storage
revert_to_startsave data to the context
sets the checkpoint
returns the values of the refs
set_timeSolve the minimization problem using the given vars and constraints.
formatted as arguments for the solver
gathers variables from solver vars, and attempts to locate any input_vars to add as well.
update_dynamicsupdate_methodsupdates the system
warningAttributes
returns all variables in the system
returns all variables in the system
all_comps_and_varssolver variables + dynamics states when dynamic_solve is True
all_system_referencesall_variable_refsreturns all variables in the system
attr_instkey mapping to lookup the key from the attribute
check_dynamicscopy_systemreturns the dataframe of the system
dynamic_compsdynamic_ratedynamic_rate_eqindicates if the system is dynamic
dynamic_stateenter_refreshenteredexit_on_failureexitedfail_revertreturns the final objective of the system, depending on mixed objective, equalities, and constraints
full_updateidentitycombine the dynamic state and the integrator rates to get the transient state of the system, but convert their keys to the target var names
integrator_ratescombine the dynamic state and the integrator rates to get the transient state of the system, but convert their keys to the target var names
integrator_varsintegratorschecks if the context has been entered and not exited
copy of slv_kw args
level_namelevel_numberlog_levelreturn a list of sorted data rows by item and filter each row to remove invalid data
opt_failrecords the state of the system
post_callbackpost_execpre_execproblem_eqproblem_idproblem_ineqproblem_inputproblem_objssolver variables
problems_dictraise_on_unknownrecords the state of the system using session
ref_attrsrevert_everyrevert_lastrun_solversave_modesave_on_exitcaches the property for the session
session_idsignal_instsignalssignals_sourcesignals_targetchecks the system's references to determine if its solveabl
solver_instsuccess_threshsystemsessionx_start- property all_components: dict
returns all variables in the system
- property all_comps: dict
returns all variables in the system
- property all_problem_vars: dict
solver variables + dynamics states when dynamic_solve is True
- property all_variables: dict
returns all variables in the system
- property attribute_sys_key_map: dict
key mapping to lookup the key from the attribute
- Type:
returns an attribute
- change_sys_var(key, value, refs=None, doset=True, attr_key_map=None)[source]
use this function to change the value of a system var and update the start state, multiple uses in the same context will not change the record preserving the start value
- Parameters:
key – a string corresponding to a ref, or an attrs.Attribute of one of the system or its component’s.
- class_cache
alias of
ProblemExec
- property dataframe: DataFrame
returns the dataframe of the system
- property dynamic_solve: bool
indicates if the system is dynamic
- establish_system(system, kw_dict, **kwargs)[source]
caches the system references, and parses the system arguments
- property final_objectives: dict
returns the final objective of the system, depending on mixed objective, equalities, and constraints
- classmethod get_extra_kws(kwargs, _check_keys={'activate': None, 'add_obj': True, 'add_vars': None, 'both_match': True, 'combos': 'default', 'deactivate': None, 'dxdt': None, 'ign_combos': None, 'ign_vars': None, 'obj': None, 'only_active': True, 'only_combos': None, 'only_vars': None, 'slv_vars': '*', 'weights': None}, rmv=False, use_defaults=True)[source]
extracts the combo input from the kwargs
- Parameters:
_check_keys (dict)
- integral_rate(t, x, dt, Xss=None, Yobj=None, **kw)[source]
provides the dynamic rate of the system at time t, and state x
- property integrator_rate_refs
combine the dynamic state and the integrator rates to get the transient state of the system, but convert their keys to the target var names
- property integrator_var_refs
combine the dynamic state and the integrator rates to get the transient state of the system, but convert their keys to the target var names
- property is_active
checks if the context has been entered and not exited
- property kwargs
copy of slv_kw args
- min_refresh(sesh=None)[source]
what things need to be refreshed per execution, this is important whenever items are replaced
- property numeric_data
return a list of sorted data rows by item and filter each row to remove invalid data
- property output_state: dict
records the state of the system
- classmethod parse_default(key, defaults, input_dict, rmv=False, empty_str=True)[source]
splits strings or lists and returns a list of options for the key, if nothing found returns None if fail set to True raises an exception, otherwise returns the default value
- post_execute(*args, **kwargs)[source]
Updates the post/both signals after the solver has been executed. This is useful for updating the system state after the solver has been executed.
- pre_execute(*args, **kwargs)[source]
Updates the pre/both signals after the solver has been executed. This is useful for updating the system state after the solver has been executed.
- print_all_info(keys=None, comps=None)[source]
Print all the information of each component’s dictionary. Parameters: key_sch (str, optional): A pattern to match dictionary keys. Only keys matching this pattern will be included in the output. comps (list, optional): A list of component sys names to filter. Only information of these components will be printed. Returns: None (except stdout :)
- Parameters:
keys (str | None)
comps (str | None)
- property problem_opt_vars: dict
solver variables
- property record_state: dict
records the state of the system using session
- property sesh
caches the property for the session
- solve_min(Xref=None, Yref=None, output=None, **kw)[source]
Solve the minimization problem using the given vars and constraints. And sets the system state to the solution depending on input of the following:
Solve the root problem using the given vars. :type Xref: :param Xref: The reference input values. :type Yref: :param Yref: The reference objective values to minimize. :type output: :param output: The output dictionary to store the results. (default: None) :param fail: Flag indicating whether to raise an exception if the solver doesn’t converge. (default: True) :type kw: :param kw: Additional keyword arguments. :return: The output dictionary containing the results.
- property solveable
checks the system’s references to determine if its solveabl
- sys_solver_constraints(add_con=None, combo_filter=True, **kw)[source]
formatted as arguments for the solver