|
14 | 14 |
|
15 | 15 | """Resolves ParameterValues to assigned values."""
|
16 | 16 | import numbers
|
17 |
| -from typing import Any, Dict, Iterator, Optional, TYPE_CHECKING, Union, cast |
| 17 | +from typing import Any, Dict, Iterator, Mapping, Optional, TYPE_CHECKING, Union, cast |
18 | 18 |
|
19 | 19 | import numpy as np
|
20 | 20 | import sympy
|
|
27 | 27 |
|
28 | 28 |
|
29 | 29 | ParamDictType = Dict['cirq.TParamKey', 'cirq.TParamValComplex']
|
| 30 | +ParamMappingType = Mapping['cirq.TParamKey', 'cirq.TParamValComplex'] |
30 | 31 | document(ParamDictType, """Dictionary from symbols to values.""") # type: ignore
|
| 32 | +document(ParamMappingType, """Immutable map from symbols to values.""") # type: ignore |
31 | 33 |
|
32 |
| -ParamResolverOrSimilarType = Union['cirq.ParamResolver', ParamDictType, None] |
| 34 | +ParamResolverOrSimilarType = Union['cirq.ParamResolver', ParamMappingType, None] |
33 | 35 | document(
|
34 | 36 | ParamResolverOrSimilarType, # type: ignore
|
35 | 37 | """Something that can be used to turn parameters into values.""",
|
@@ -70,12 +72,16 @@ def __init__(self, param_dict: 'cirq.ParamResolverOrSimilarType' = None) -> None
|
70 | 72 | return # Already initialized. Got wrapped as part of the __new__.
|
71 | 73 |
|
72 | 74 | self._param_hash: Optional[int] = None
|
73 |
| - self.param_dict = cast(ParamDictType, {} if param_dict is None else param_dict) |
| 75 | + self._param_dict = cast(ParamDictType, {} if param_dict is None else param_dict) |
74 | 76 | for key in self.param_dict:
|
75 | 77 | if isinstance(key, sympy.Expr) and not isinstance(key, sympy.Symbol):
|
76 | 78 | raise TypeError(f'ParamResolver keys cannot be (non-symbol) formulas ({key})')
|
77 | 79 | self._deep_eval_map: ParamDictType = {}
|
78 | 80 |
|
| 81 | + @property |
| 82 | + def param_dict(self) -> ParamMappingType: |
| 83 | + return self._param_dict |
| 84 | + |
79 | 85 | def value_of(
|
80 | 86 | self, value: Union['cirq.TParamKey', 'cirq.TParamValComplex'], recursive: bool = True
|
81 | 87 | ) -> 'cirq.TParamValComplex':
|
|
0 commit comments