zoomy_core.symsolver.hooks#
Function hooks: a model’s operators call an opaque function hook("name") (a SymPy function
the derivation keeps opaque, never an aux field); the solver setting functions={"name": callable}
implements it on the Python backends (NumPy, JAX). The C++ backends (foam, AMReX) refuse a hook
at setup.
A derivative the pipeline takes of a hook (source Jacobians, the flux’s quasilinear matrix)
appears as Derivative(f(...), arg) or Subs(Derivative(...)); HookFunction.derivative
says how it is printed: HookDerivative.zero, the user’s partial derivatives (printed like the
function), or HookDerivative.auto (a SymPy Lambda: SymPy differentiates it on every Python
backend; a callable: JAX AD, so JAX only).
Module Contents#
Classes#
How the derivative of a hook is printed. |
|
A hook’s implementation |
|
|
|
A backend’s hooks: |
Functions#
The opaque function |
|
Decorator: |
|
The names of the hooks |
|
Every hook the operators of |
|
The C++ backends: raise |
|
Raise the |
Data#
API#
- zoomy_core.symsolver.hooks.HOOKS_KEY#
‘zoomy_hooks’
- zoomy_core.symsolver.hooks.hook(name)#
The opaque function
namefor a model’s operators (real valued); the solver’sfunctions[name]implements it.
- class zoomy_core.symsolver.hooks.HookDerivative#
Bases:
zoomy_core.misc.options.OptionHow the derivative of a hook is printed.
Initialization
Initialize self. See help(type(self)) for accurate signature.
- zero#
‘zero’
- auto#
‘auto’
- class zoomy_core.symsolver.hooks.HookFunction(function, derivative=HookDerivative.auto)#
A hook’s implementation
function(a callable of the backend’s arrays, or a SymPyLambda) and itsderivative: aHookDerivative, a sequence of callables (one partial per argument), or one callable returning all partials.Initialization
Validate
functionandderivative.- property symbolic#
Whether the function is a SymPy
Lambda(inlined, differentiated by SymPy).
- zoomy_core.symsolver.hooks.hook_function(derivative=HookDerivative.auto)#
Decorator:
@hook_function(derivative=...)makes aHookFunction.
- class zoomy_core.symsolver.hooks.FunctionsParam(default: dict[Any, Any] | None = t.cast('dict[t.Any, t.Any] | None', Undefined), *, allow_None: bool = t.cast('bool', Undefined), **params: typing_extensions.Unpack[param.parameters._ClassSelectorKwargs])#
Bases:
param.Dictfunctions: hook name (an identifier) -> callable,sp.LambdaorHookFunction.Initialization
Initialize a new :class:
Parameterobject with the specified attributes.Parameters
default(Any, optional): The owning class’s value for the attribute represented by this parameter, which can be overridden in an instance. Default isNone.default_factory(callable, optional): A callable used to generate the attribute value. It can be provided directly (in which case it is invoked with no arguments) or wrapped in a :class:DefaultFactoryfor more advanced behavior (in which case it receivescls,self, andparameteras arguments). When specified,default_factorytakes precedence overdefault. The factory is invoked once the :class:Parameterizedinstance is initialized... versionadded:: 2.3.0
doc(str | None, optional): A documentation string describing the purpose of the parameter. Default isNone.label(str | None, optional): An optional text label used when displaying this parameter, such as in a listing. If not specified, the parameter’s attribute name in the owning :class:Parameterizedobject is used.precedence(float | None, optional): A numeric value, usually in the range 0.0 to 1.0, that determines the order of the parameter in a listing or user interface. A negative precedence indicates a parameter that should be hidden in such listings. Default isNone.instantiate(bool, optional): Whether the default value of this parameter will be deepcopied when a :class:Parameterizedobject is instantiated (True), or if the single default value will be shared by all Parameterized instances (False, the default). For an immutableParametervalue, it is best to leaveinstantiateat the default ofFalse, so that a user can choose to change the value at theParameterizedinstance level (affecting only that instance) or at the :class:Parameterizedclass or superclass level (affecting all existing and future instances of that class or superclass). For a mutableParametervalue, the default ofFalseis also appropriate if you want all instances to share the same value state, e.g. if they are each simply referring to a single global object like a singleton. If instead eachParameterizedshould have its own independently mutable value, instantiate should be set toTrue, but note that there is then no simple way to change the value of this parameter at the class or superclass level, because each instance, once created, will then have an independently deepcopied value. Default isFalse.constant(bool, optional): IfTrue, the parameter value can only be set at the class level or in a :class:Parameterizedconstructor call. The value is otherwise constant on theParameterizedinstance, once it has been constructed. Default isFalse.readonly(bool, optional): IfTrue, the parameter value cannot be modified at the class or instance level. Default isFalse.pickle_default_value(bool, optional): Whether the default value should be pickled. Set toFalsein rare cases, such as system-specific file paths... deprecated:: 2.3.0
allow_None(bool, optional): IfTrue, allowsNoneas a valid parameter value. If the default value isNone, this is automatically set toTrue. Default isFalse.per_instance(bool, optional): Whether to create a separateParameterobject for each instance of theParameterizedclass (True), or share the sameParameterobject across all instances (False). See alsoinstantiate, which is conceptually similar but affects the parameter value rather than the parameter object. Default isTrue.allow_refs(bool, optional): IfTrue, allows linking parameter references to this parameter, meaning the value will automatically reflect the current value of the reference that is passed in. Default isFalse.nested_refs(bool, optional): IfTrueandallow_refs=True, inspects nested objects (e.g., dictionaries, lists, slices, tuples) for references and resolves them automatically. Default isFalse.metadata(Mapping, optional): An arbitrary mapping, to be used to store additional metadata than cannot be declared with the other attributes. Useful for third-party libraries to extend Param. Default isNone... versionadded:: 2.3.0
Examples
Define a parameter with a default value:
import param class MyClass(param.Parameterized): … my_param = param.Parameter(default=10, doc=”An example parameter.”) instance = MyClass() instance.my_param 10
Use a constant parameter:
class ConstantExample(param.Parameterized): … my_param = param.Parameter(default=5, constant=True) instance = ConstantExample() instance.my_param = 10 # Raises an error … TypeError: Constant parameter ‘my_param’ cannot be modified.
- exception zoomy_core.symsolver.hooks.HookError#
Bases:
NotImplementedErrorA hook (or its derivative) a backend cannot print.
Initialization
Initialize self. See help(type(self)) for accurate signature.
- zoomy_core.symsolver.hooks.hook_names(expr)#
The names of the hooks
exprcalls.
- class zoomy_core.symsolver.hooks.Hooks(functions, grad=None)#
A backend’s hooks:
lower(expr)replaces hook derivatives (and inlines SymPy hooks);moduleholds the callables the lowered expressions call.grad(f, i)differentiates a callable (JAX:jax.grad);None:HookDerivative.autoof a callable is refused.Initialization
Wrap every plain callable as a
HookFunction(HookDerivative.auto).- lower(expr)#
exprwith the hook derivatives printable and SymPy hooks inlined (unchanged when it calls no hook).
- zoomy_core.symsolver.hooks.check_functions(functions, systems)#
Every hook the operators of
systems(NSMs) call has a function and every function is called; raisesValueError(with “did you mean”).
- zoomy_core.symsolver.hooks.refuse_hooks(systems, backend, functions=None)#
The C++ backends: raise
NotImplementedErrorfor a hook the kernels ofsystems(NSMs) call, or anyfunctionsset.
- zoomy_core.symsolver.hooks.refuse_used(refused, owner, source)#
Raise the
HookErrorof a refused kernel ({slot: error}) the printedsourcecalls asowner.slot.