def _mapped_single_loop(self, repetition_id: Optional[str] = None ) -> 'cirq.Circuit': if self._cached_mapped_single_loop is None: circuit = self.circuit.unfreeze() if self.qubit_map: circuit = circuit.transform_qubits( lambda q: self.qubit_map.get(q, q)) if isinstance(self.repetitions, INT_CLASSES) and self.repetitions < 0: circuit = circuit**-1 if self.measurement_key_map: circuit = protocols.with_measurement_key_mapping( circuit, self.measurement_key_map) if self.param_resolver: circuit = protocols.resolve_parameters(circuit, self.param_resolver, recursive=False) object.__setattr__(self, '_cached_mapped_single_loop', circuit) circuit = cast(circuits.Circuit, self._cached_mapped_single_loop) if repetition_id: circuit = protocols.with_rescoped_keys(circuit, (repetition_id, )) return protocols.with_rescoped_keys(circuit, self.parent_path, bindable_keys=self.extern_keys)
def _mapped_single_loop(self, repetition_id: Optional[str] = None ) -> 'cirq.Circuit': circuit = self._mapped_any_loop if repetition_id: circuit = protocols.with_rescoped_keys(circuit, (repetition_id, )) return protocols.with_rescoped_keys(circuit, self.parent_path, bindable_keys=self._extern_keys)
def _with_rescoped_keys_( self, path: Tuple[str, ...], bindable_keys: FrozenSet['cirq.MeasurementKey'] ) -> 'ClassicallyControlledOperation': conds = [ protocols.with_rescoped_keys(c, path, bindable_keys) for c in self._conditions ] sub_operation = protocols.with_rescoped_keys(self._sub_operation, path, bindable_keys) return sub_operation.with_classical_controls(*conds)
def _with_rescoped_keys_( self, path: Tuple[str, ...], bindable_keys: FrozenSet['cirq.MeasurementKey'] ): new_gate = protocols.with_rescoped_keys(self.gate, path, bindable_keys) if new_gate is self.gate: return self return new_gate.on(*self.qubits)
def _with_rescoped_keys_( self, path: Tuple[str, ...], bindable_keys: FrozenSet['cirq.MeasurementKey'], ): return self.with_key( protocols.with_rescoped_keys(self.mkey, path, bindable_keys))
def _with_rescoped_keys_( self, path: Tuple[str, ...], bindable_keys: FrozenSet['cirq.MeasurementKey'], ): return Moment( protocols.with_rescoped_keys(op, path, bindable_keys) for op in self.operations)
def _with_rescoped_keys_( self, path: Tuple[str, ...], bindable_keys: FrozenSet['cirq.MeasurementKey'], ): return MixedUnitaryChannel( mixture=self._mixture, key=protocols.with_rescoped_keys(self._key, path, bindable_keys), )
def _with_rescoped_keys_( self, path: Tuple[str, ...], bindable_keys: FrozenSet['cirq.MeasurementKey'], ): return KrausChannel( kraus_ops=self._kraus_ops, key=protocols.with_rescoped_keys(self._key, path, bindable_keys), )
def mapped_circuit(self, deep: bool = False) -> 'cirq.Circuit': """Applies all maps to the contained circuit and returns the result. Args: deep: If true, this will also call mapped_circuit on any CircuitOperations this object contains. Returns: The contained circuit with all other member variables (repetitions, qubit mapping, parameterization, etc.) applied to it. This behaves like `cirq.decompose(self)`, but preserving moment structure. """ circuit = self.circuit.unfreeze() if self.qubit_map: circuit = circuit.transform_qubits( lambda q: self.qubit_map.get(q, q)) if self.repetitions < 0: circuit = circuit**-1 if self.measurement_key_map: circuit = protocols.with_measurement_key_mapping( circuit, self.measurement_key_map) if self.param_resolver: circuit = protocols.resolve_parameters(circuit, self.param_resolver, recursive=False) if self.repetition_ids: if not protocols.is_measurement(circuit): circuit = circuit * abs(self.repetitions) else: circuit = circuits.Circuit( protocols.with_rescoped_keys(circuit, (rep, )) for rep in self.repetition_ids) circuit = protocols.with_rescoped_keys(circuit, self.parent_path, bindable_keys=self.extern_keys) if deep: circuit = circuit.map_operations(lambda op: op.mapped_circuit( deep=True) if isinstance(op, CircuitOperation) else op) return circuit