View source on GitHub |
Resolves parameters to actual values.
cirq.ParamResolver(
param_dict: 'cirq.ParamResolverOrSimilarType' = None
) -> None
Used in the notebooks
Used in the tutorials |
---|
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.
Raises | |
---|---|
TypeError if formulas are passed as keys. |
Attributes | |
---|---|
param_dict
|
A dictionary from the ParameterValue key (str) to its assigned value. |
Methods
value_of
value_of(
value: Union['cirq.TParamKey', 'cirq.TParamValComplex'],
recursive: bool = True
) -> 'cirq.TParamValComplex'
Attempt to resolve a parameter to its assigned value.
Scalars 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. |
sympy.SympifyError
|
If the resulting value cannot be interpreted. |
__bool__
__bool__() -> bool
__eq__
__eq__(
other
)
Return self==value.
__getitem__
__getitem__(
key: Union['cirq.TParamKey', 'cirq.TParamValComplex']
) -> 'cirq.TParamValComplex'
__iter__
__iter__() -> Iterator[Union[str, sympy.Expr]]
__ne__
__ne__(
other
)
Return self!=value.