engforge.problem_context.Problem

class Problem(system, kw_dict=None, Xnew=None, ctx_fail_new=False, **opts)[source]

Bases: ProblemExec, DataframeMixin

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_state

apply_post_signals

applies all post signals

apply_pre_signals

applies all pre signals

change_sys_var

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_context

cls_is_active

checks if the cache has a session

critical

debug

debug_levels

debug the levels of the context

discard_contexts

discard all contexts

error

error_action

handles the error action wrt to the problem

establish_system

caches the system references, and parses the system arguments

exit_action

handles the exit action wrt system

exit_and_revert

exit_to_level

exit_with_state

filter_vars

selects only settable refs

format_columns

full_refresh

a more time consuming but throughout refresh of the system

get_extra_kws

extracts the combo input from the kwargs

get_parent_key

returns the parent key of the key

get_ref_values

returns the values of the refs

get_sesh

get the session

handle_solution

info

integral_rate

provides the dynamic rate of the system at time t, and state x

integrate

min_refresh

what things need to be refreshed per execution, this is important whenever items are replaced

msg

parse_default

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

persist_contexts

convert all contexts to a new storage format

pos_obj

converts an objective to a positive value

post_execute

Updates the post/both signals after the solver has been executed.

post_update_system

updates the system

pre_execute

Updates the pre/both signals after the solver has been executed.

print_all_info

Print all the information of each component's dictionary.

refresh_references

refresh the system references

reset_contexts

reset all contexts to a new storage format

reset_data

reset the data storage

revert_to_start

save_data

save data to the context

set_checkpoint

sets the checkpoint

set_ref_values

returns the values of the refs

set_time

smart_split_dataframe

splits dataframe between constant values and variants

solve_min

Solve the minimization problem using the given vars and constraints.

sys_solver_constraints

formatted as arguments for the solver

sys_solver_objectives

gathers variables from solver vars, and attempts to locate any input_vars to add as well.

update_dynamics

update_methods

update_system

updates the system

warning

Attributes

all_components

returns all variables in the system

all_comps

returns all variables in the system

all_comps_and_vars

all_problem_vars

solver variables + dynamics states when dynamic_solve is True

all_system_references

all_variable_refs

all_variables

returns all variables in the system

attr_inst

attribute_sys_key_map

key mapping to lookup the key from the attribute

check_dynamics

copy_system

dataframe

returns the dataframe of the system

dataframe_constants

dataframe_variants

dynamic_comps

dynamic_rate

dynamic_rate_eq

dynamic_solve

indicates if the system is dynamic

dynamic_state

enter_refresh

entered

exit_on_failure

exited

fail_revert

final_objectives

returns the final objective of the system, depending on mixed objective, equalities, and constraints

full_update

identity

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

integrator_rates

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

integrator_vars

integrators

is_active

checks if the context has been entered and not exited

kwargs

copy of slv_kw args

level_name

level_number

log_level

numeric_data

return a list of sorted data rows by item and filter each row to remove invalid data

opt_fail

output_state

records the state of the system

post_callback

post_exec

pre_exec

problem_eq

problem_id

problem_ineq

problem_input

problem_objs

problem_opt_vars

solver variables

problems_dict

raise_on_unknown

record_state

records the state of the system using session

ref_attrs

revert_every

revert_last

run_solver

save_mode

save_on_exit

sesh

caches the property for the session

session_id

signal_inst

signals

signals_source

signals_target

skip_plot_vars

accesses '_skip_plot_vars' if it exists, otherwise returns empty list

solveable

checks the system's references to determine if its solveabl

solver_inst

success_thresh

system

session

x_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

apply_post_signals()

applies all post signals

apply_pre_signals()

applies all pre signals

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)

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

classmethod cls_is_active()

checks if the cache has a session

property dataframe: DataFrame

returns the dataframe of the system

debug_levels()

debug the levels of the context

discard_contexts()

discard all contexts

property dynamic_solve: bool

indicates if the system is dynamic

error_action(error)

handles the error action wrt to the problem

establish_system(system, kw_dict, **kwargs)

caches the system references, and parses the system arguments

exit_action()

handles the exit action wrt system

filter_vars(refs)

selects only settable refs

Parameters:

refs (list)

property final_objectives: dict

returns the final objective of the system, depending on mixed objective, equalities, and constraints

full_refresh(sesh=None)

a more time consuming but throughout refresh of the system

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)

extracts the combo input from the kwargs

Parameters:

_check_keys (dict)

get_parent_key(key, look_back_num=1)

returns the parent key of the key

get_ref_values(refs=None)

returns the values of the refs

get_sesh(sesh=None)

get the session

integral_rate(t, x, dt, Xss=None, Yobj=None, **kw)

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)

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)

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

persist_contexts()

convert all contexts to a new storage format

pos_obj(ref)

converts an objective to a positive value

post_execute(*args, **kwargs)

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.

post_update_system(*args, **kwargs)

updates the system

pre_execute(*args, **kwargs)

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)

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

refresh_references(sesh=None)

refresh the system references

reset_contexts(fail_if_discardmode=True)

reset all contexts to a new storage format

reset_data()

reset the data storage

save_data(index=None, force=False, **add_data)

save data to the context

property sesh

caches the property for the session

set_checkpoint()

sets the checkpoint

set_ref_values(values, refs=None, scope='sref')

returns the values of the refs

property skip_plot_vars: list

accesses ‘_skip_plot_vars’ if it exists, otherwise returns empty list

smart_split_dataframe(df=None, split_groups=0, key_f=<function <lambda>>)

splits dataframe between constant values and variants

solve_min(Xref=None, Yref=None, output=None, **kw)

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)

formatted as arguments for the solver

sys_solver_objectives(**kw)

gathers variables from solver vars, and attempts to locate any input_vars to add as well. use exclude_vars to eliminate a variable from the solver

update_system(*args, **kwargs)

updates the system