File tree 1 file changed +11
-3
lines changed 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -96,6 +96,9 @@ class CircuitOperation(ops.Operation):
96
96
_cached_measurement_key_objs : Optional [AbstractSet ['cirq.MeasurementKey' ]] = dataclasses .field (
97
97
default = None , init = False
98
98
)
99
+ _cached_control_keys : Optional [AbstractSet ['cirq.MeasurementKey' ]] = dataclasses .field (
100
+ default = None , init = False
101
+ )
99
102
100
103
circuit : 'cirq.FrozenCircuit'
101
104
repetitions : int = 1
@@ -208,9 +211,14 @@ def _measurement_key_names_(self) -> AbstractSet[str]:
208
211
return {str (key ) for key in self ._measurement_key_objs_ ()}
209
212
210
213
def _control_keys_ (self ) -> AbstractSet ['cirq.MeasurementKey' ]:
211
- if not protocols .control_keys (self .circuit ):
212
- return frozenset ()
213
- return protocols .control_keys (self .mapped_circuit ())
214
+ if self ._cached_control_keys is None :
215
+ keys = (
216
+ frozenset ()
217
+ if not protocols .control_keys (self .circuit )
218
+ else protocols .control_keys (self .mapped_circuit ())
219
+ )
220
+ object .__setattr__ (self , '_cached_control_keys' , keys )
221
+ return self ._cached_control_keys # type: ignore
214
222
215
223
def _parameter_names_ (self ) -> AbstractSet [str ]:
216
224
return {
You can’t perform that action at this time.
0 commit comments