cirq.study.ParamResolver

Resolves parameters to actual values.

A parameter is a variable whose value has not been determined. A ParamResolver is an object that can be used to assign values for these variables.

ParamResolvers are hashable; their param_dict must not be mutated.

param_dict A dictionary from the ParameterValue key (str) to its assigned value.

Methods

value_of

View source

Attempt to resolve a parameter to its assigned value.

Floats are returned without modification. Strings are resolved via the parameter dictionary with exact match only. Otherwise, strings are considered to be sympy.Symbols with the name as the input string.

A sympy.Symbol is first checked for exact match in the parameter dictionary. Otherwise, it is treated as a sympy.Basic.

A sympy.Basic is resolved using sympy substitution.

Note that passing a formula to this resolver can be slow due to the underlying sympy library. For circuits relying on quick performance, it is recommended that all formulas are flattened before-hand using cirq.flatten or other means so that formula resolution is avoided. If unable to resolve a sympy.Symbol, returns it unchanged. If unable to resolve a name, returns a sympy.Symbol with that name.

Args
value The parameter to try to resolve.
recursive Whether to recursively evaluate formulas.

Returns
The value of the parameter as resolved by this resolver.

Raises
RecursionError if the ParamResolver detects a loop in recursive resolution.

__bool__

View source

__eq__

View source

Return self==value.

__getitem__

View source

__iter__

View source

__ne__

View source

Return self!=value.