engforge.attr_solver.Solver
- class Solver(name, default, validator, repr, cmp, hash, init, inherited, metadata=None, type=None, converter=None, kw_only=False, eq=None, eq_key=None, order=None, order_key=None, on_setattr=None, alias=None)[source]
Bases:
ATTR_BASEsolver creates subclasses per solver balance
Methods
adds a type constraint to the solver.
validates onetime A method to validate the kwargs passed to the define method
collects all the attribute instances for a system
collects all the attributes for a system
Defines an equality constraint based on a required lhs of equation, and an optional rhs, the difference of which will be driven to zero
Defines an inequality constraint
add the config class, and perform checks with `class_validate) :returns: [optional] a dictionary of options to be used in the make_attribute method
validates the instance given attr's init routine
Defines an equality constraint based on a required lhs of equation, and an optional rhs, the difference of which will be driven to zero
check constraints on the system, return its index position if found, else None.
Defines an inequality constraint
Create an instance of the instance_class
Defines a solver variable for optimization in the class, constraints defined on this solver will correspond to the limits of that variable :type var:
str:param var: The var attribute for the solver variable.taking a component or system class as possible input valid input is later validated as an instance of that class or subclass
A method to validate the kwargs passed to the define method
Copy self and apply changes.
from_counting_attrhandles the instance, override as you wish
makes an attrs.Attribute for the class
make_factoryDefines a solver variable for optimization in the class, constraints defined on this solver will correspond to the limits of that variable
Defines a solver variable for optimization in the class, constraints defined on this solver will correspond to the limits of that variable
process_combosreturn all subclasses of components, including their subclasses :type out: :param out: out is to pass when the middle of a recursive operation, do not use it!
unpack_atrsAttributes
namedefaultvalidatorrepreqeq_keyorderorder_keyhashinitmetadatatypeconverterkw_onlyinheritedon_setattraliasallow_constraint_overrideattr_prefixcombosdefault_optionslhsnone_okrhstemplate_classvarslvtypeconstraintsnormalizeactiveconfig_cls- classmethod add_var_constraint(value, kind='min', **kwargs)[source]
adds a type constraint to the solver. If value is numeric it is used as a bound with scipy optimize.
- If value is a function it should be of the form value(Xarray) and will establish an inequality constraint that var var must be:
less than for max
more than for min
During the evaluation of the limit function system.X should be set, and pre_execute() have already run.
- Parameters:
type – str, must be either min or max with var value comparison, or with a function additionally eq,ineq (same as max(0)) can be used
- Value:
either a numeric (int,float), or a function, f(system)
- classmethod class_validate(instance, **kwargs)[source]
validates onetime A method to validate the kwargs passed to the define method
- classmethod collect_attr_inst(system, handle_inst=True)
collects all the attribute instances for a system
- Return type:
dict
- classmethod collect_cls(system)
collects all the attributes for a system
- Return type:
dict
- classmethod con_eq(lhs, rhs=0, **kwargs)
Defines an equality constraint based on a required lhs of equation, and an optional rhs, the difference of which will be driven to zero
- Parameters:
lhs (system_property)
rhs (system_property)
- classmethod con_ineq(lhs, rhs=0, **kwargs)
Defines an inequality constraint
- Parameters:
lhs (str | system_property | callable | float | int)
rhs (str | system_property | callable | float | int)
- classmethod configure_for_system(name, config_class, cb=None, **kwargs)[source]
add the config class, and perform checks with `class_validate) :returns: [optional] a dictionary of options to be used in the make_attribute method
- classmethod configure_instance(instance, attribute, value)
validates the instance given attr’s init routine
- classmethod constraint_equality(lhs, rhs=0, **kwargs)[source]
Defines an equality constraint based on a required lhs of equation, and an optional rhs, the difference of which will be driven to zero
- Parameters:
lhs (system_property)
rhs (system_property)
- classmethod constraint_exists(**kw)[source]
check constraints on the system, return its index position if found, else None.
- classmethod constraint_inequality(lhs, rhs=0, **kwargs)[source]
Defines an inequality constraint
- Parameters:
lhs (str | system_property | callable | float | int)
rhs (str | system_property | callable | float | int)
- classmethod create_instance(system)[source]
Create an instance of the instance_class
- Return type:
- Parameters:
system (System)
- classmethod declare_var(var, **kwargs)[source]
Defines a solver variable for optimization in the class, constraints defined on this solver will correspond to the limits of that variable :type var:
str:param var: The var attribute for the solver variable. :param combos: The combinations of the solver variable. :return: The setup class for the solver variable.- Parameters:
var (str)
- classmethod define(**kwargs)
taking a component or system class as possible input valid input is later validated as an instance of that class or subclass
- classmethod define_validate(**kwargs)
A method to validate the kwargs passed to the define method
- evolve(**changes)
Copy self and apply changes.
This works similarly to attrs.evolve but that function does not work with Attribute.
It is mainly meant to be used for transform-fields.
Added in version 20.3.0.
- classmethod handle_instance(canidate)
handles the instance, override as you wish
- instance_class
alias of
SolverInstance
- classmethod make_attribute(name, comp_class, **kwargs)
makes an attrs.Attribute for the class
- classmethod obj(obj, **kwargs)
Defines a solver variable for optimization in the class, constraints defined on this solver will correspond to the limits of that variable
- Parameters:
obj (
str) – The var attribute for the solver variable.combos – The combinations of the solver variable.
- Vara kind:
the kind of optimization, either min or max
- Returns:
The setup class for the solver variable.
- classmethod objective(obj, **kwargs)[source]
Defines a solver variable for optimization in the class, constraints defined on this solver will correspond to the limits of that variable
- Parameters:
obj (
str) – The var attribute for the solver variable.combos – The combinations of the solver variable.
- Vara kind:
the kind of optimization, either min or max
- Returns:
The setup class for the solver variable.
- classmethod subclasses(out=None)
return all subclasses of components, including their subclasses :type out: :param out: out is to pass when the middle of a recursive operation, do not use it!