engforge.system_reference.Ref

class Ref(comp, key, use_call=True, allow_set=True, eval_f=None)[source]

Bases: object

A way to create portable references to system’s and their component’s properties, ref can also take a key to a zero argument function which will be evald. This is useful for creating an adhoc optimization problems dynamically between variables. However use must be carefully controlled to avoid circular references, and understanding the safe use of the refset_input and refset_get methods (changing state on actual system).

A dictionary can be used as a component, and the key will be used to access the value in the dictionary.

The key can be a callable of (*args,**kw) only in which case Ref.value(*args,**kw) will take input, and the ref will be evaluated as the result of the callable (allow_set=False), this renders the component unused, and disables the ability to set the value of the reference.

The ability to set this ref with another on key input allows for creating a reference that is identical to another reference except for the component provided if it is not None.

Methods

copy

copy the reference, and make changes to the copy

refset_get

refset_input

change a set of refs with a dictionary of values.

set

set_value

setup_calls

caches anonymous functions for value and logging speedup

value

Attributes

comp

key

use_call

use_dict

allow_set

eval_f

key_override

hxd

attr_type

full_key

copy(**changes)[source]

copy the reference, and make changes to the copy

refset_input(delta_dict, chk=True, fail=True, warn=True, scope='ref')

change a set of refs with a dictionary of values. If chk is True k will be checked for membership in refs

setup_calls()[source]

caches anonymous functions for value and logging speedup