PlasmaCalcs.quantities.quantity_tools.DecoratingVars

class PlasmaCalcs.quantities.quantity_tools.DecoratingVars(known_calcs=None)

Bases: DecoratingCalcs

Decorating functions to put loadable vars into a dict (self.known_calcs).
(e.g., self.known_calcs will be QuantityLoader.KNOWN_VARS; see MetaQuantTracking for details.)
known_calcs: None or dict
will store known calcs; dict of {name: LoadableVar} pairs.
Example: known_var = DecoratingCalcs(storage_dict)
@known_var
def get_var1(…):
@known_var(name=’coolvar’, deps=[‘var1’])
def get_var2(…):
# at this point, we have:
# known_var.known_calcs == {‘var1’: LoadableQuantity(‘get_var1’),
# ‘coolvar’: LoadableQuantity(‘get_var2’, deps=[‘var1’])}.
__init__(known_calcs=None)

Methods

__init__([known_calcs])

decorator(*[, name, aliases, deps, ...])

track_f(f, *[, name, aliases, deps, ...])

decorator(*, name=None, aliases=[], deps=[], attr_deps=[], value_deps=[], dims=None, load_across_dims=None, ignores_dims=[], reduces_dims=[], partition_across_dim=None, partition_deps=None)
returns decorator for quant calculator f(self, *args, **kw), which returns f unchanged…
but also sets self.known_calcs[name] = LoadableQuantity(f.__name__, deps=deps)
(note - actually uses self.loadable_quantity_cls instead of LoadableQuantity)
name: None or str
if provided, tells name of this quantity (i.e., the key in self.known_calcs)
None –> use {name} from f.__name__ which looks like “get_{name}”.
aliases: list
if any aliases are provided, also add, for alias in aliases:
self.known_calcs[alias] = self.known_calcs[name]
deps: list of str/int/tuple/dict/callable
list of dependencies for this quant. Each dependency is one of the following:
- a str, indicating a known var or pattern name,
- an int, indicating a group index from a pattern match,
- a 2-tuple of (non-tuple-dep, dict),
where dict tells any values essential to set via quantity_loader.using(**dict),
in order to properly determine deps.
E.g. (‘n’, {‘fluid’: ELECTRON}) for ‘depends on n when self.fluid=electron’.
Note: mostly intended for internal use (in value_deps). It’s usually preferable to
just define a different variable, e.g. ‘ne’ which will set values appropriately.
- a dict with length 1, with
key = int or tuple of ints, specifying which groups are relevant.
dep will utilize info about groups = _match.groups().
val = str, or callable f -> str or iterable.
str –> val.format(**group_info), where
group_info = {f’group{i}’: groups[i] for i in key},
replacing groups[i] with ‘’ if groups[i] is None.
callable f –> f(group_info), where
group_info = {i: groups[i] for i in key}
- a callable of the form f(quantity_loader, var, groups) -> str or iterable,
which tells the var name(s) associated with this dependency,
where: quantity_loader is a QuantityLoader instance,
var is the matched var,
and groups=_match.groups() if _match provided else None.
attr_deps: list of 2-tuples of (str, dict or str)
list of attr-based dependencies for this quant. Each dependency is:
(attr, lookup), where lookup.get(v, []) tells str or list of deps associated with v,
where v=quantity_loader.attr.
if ‘__default__’ in lookup, use lookup.get(v, lookup[‘__default__’]) instead.
str lookup –> lookup = getattr(quantity_loader, lookup).
value_deps: list of 2-tuples of (str, dict or str)
list of value-based dependencies for this quant. Each dependency is:
(var, lookup), where lookup.get(val, []) tells str or list of deps associated with val,
for all unique vals in quantity_loader(var).
Each dep associated with val may be str/int/callable, similar to deps.
if ‘__default__’ in lookup, use lookup.get(v, lookup[‘__default__’]) instead.
str lookup –> lookup = getattr(quantity_loader, lookup).
dims: None or list of strings
dimensions associated directly with this quantity. E.g. [‘fluid’, ‘snap’]
None –> this quant is not directly associated with any dims.
load_across_dims: None or list of strings
if provided, the returned decorator(f) will actually wrap f to use load_across_dims:
result(f)(self, …) returns self.load_across_dims(f, …, dims=load_across_dims).
To indicate dim dependencies without adjusting f, use kwarg dims, instead.
ignores_dims: list of strings
dimensions which the result ignores, even if the dependencies don’t ignore.
E.g. ‘mod_(.+)’ has ignores_dims=[‘component’],
because it provides the same result regardless of obj.component.
reduces_dims: list of strings
dimensions which the result reduces along.
E.g. ‘ldebye_subset’ has reduces_dims=[‘fluid’],
because the result doesn’t have ‘fluid’ dim even though it depends on obj.fluid.
partition_across_dim: None or 2-tuple of (dim, partitioner)
if provided, the returned decorator(f) will actually wrap f:
result(f)(self, …) partitions across dim and provides partitioner as kwarg input,
then rejoins along dim afterwards.
currently, only supports partitioning across 1 dim per f.
partitioner should be a string, and will be added to deps.
partition_deps: None, str, or dict
if provided, tells lookup from partitioner value to additional dep var name(s).
(only allowed if partition_across_dim is provided.)
Equivalent to using value_deps=[(partitioner, partition_deps)].
str –> will use lookup = getattr(quantity_loader, partition_deps).

E.g. {‘saha’: ‘ionfrac_saha’, ‘SINGLE_FLUID’: [‘ne’, ‘SF_n’]},
when partition_across_dim=(‘fluid’, ‘ionfrac_type’),
–> add ‘ionfrac_saha’ to deps if ‘saha’ in self(‘ionfrac_type’),
and add ‘ne’ and ‘SF_n’ to deps if ‘SINGLE_FLUID’ in self(‘ionfrac_type’).
and, this example is equivalent to using value_deps=
[(‘ionfrac_type’, {‘saha’: ‘ionfrac_saha’, ‘SINGLE_FLUID’: [‘ne’, ‘SF_n’]})]
loadable_quantity_cls

alias of LoadableVar

track_f(f, *, name=None, aliases=[], deps=[], attr_deps=[], value_deps=[], dims=None, ignores_dims=[], reduces_dims=[])
add f to self.known_calcs as a LoadableQuantity.
See help(self.decorator) for details on parameters.