engforge.problem_context

The ProblemExec 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.

The ProblemExec class allows entrance to a its context to the same instance until finally the last exit is called. The first entrance to the context will create the instance, each subsequent entrance will return the same instance. The ProblemExec arguments are set the first time and remove keyword arguments from the input dictionary (passed as a dict ie stateful) to subsequent methods. This isn’t technically a singleton pattern, but it does provide a similar interface. Instead mutliple problem instances will be clones of the first instance, with the optional difference of input/output/event criteria. The first instance will be returned by each context entry, so for that reason it may always appear to have same instance, however each instance is unique in a recusive setting so it may record its own state and be reverted to its own state as per the options defined.

#TODO: allow update of kwargs on re-entrance

## Example: .. code-block:: python

#Application code (arguments passed in kw) with ProblemExec(sys,combos=’default’,slv_vars’*’,**kw) as pe:

pe._sys_refs #get the references and compiled problem for i in range(10):

pe.solve_min(pe.Xref,pe.Yref,**other_args) pe.set_checkpoint() #save the state of the system pe.save_data()

#Solver Module (can use without knowledge of the runtime system) with ProblemExec(sys,{},Xnew=Xnext,ctx_fail_new=True) as pe:

#do revertable math on the state of the system without concern for the state of the system

# Combos Selection By default no arguments run will select all active items with combo=”default”. The combos argument can be used to select a specific set of combos, a outer select. From this set, the ign_combos and only_combos arguments can be used to ignore or select specific combos based on exclusion or inclusion respectively.

# Parameter Name Selection The slv_vars argument can be used to select a specific set of solvables. From this set, the ign_vars and only_vars arguments can be used to ignore or select specific solvables based on exclusion or inclusion respectively. The add_vars argument can be used to add a specific set of solvables to the solver.

# Active Mode Handiling The only_active argument can be used to select only active items. The activate and deactivate arguments can be used to activate or deactivate specific solvables.

add_obj can be used to add an objective to the solver.

# Root Parameter Determination: Any session’s may access root session parameters defined in the root_parameters dictionary like converged, or data can be accessed by calling session.<parm> this eventually calls root._<parm> via the __getattr__ method.

# Exit Mode Handling

The ProblemExec supports the following exit mode handling vars:

  • fail_revert: Whether to raise an error if no solvables are selected. Default is True.

  • revert_last: Whether to revert the last change. Default is True.

  • revert_every: Whether to revert every change. Default is True.

  • exit_on_failure: Whether to exit on first failure. Default is True.

These vars control the behavior of the ProblemExec when an error occurs or when no solvables are selected.

Functions

refget_attr

refget_key

Classes

ProbLog

Initialize a filter.

Problem

Initializes the ProblemExec.

ProblemExec

Represents the execution context for a problem in the system.

Exceptions

IllegalArgument

an exception to exit the problem context as specified

ProblemExit(prob[, revert])

an exception to exit the problem context, without error

ProblemExitAtLevel(prob, level[, revert])

an exception to exit the problem context, without error