def _with_key_path_prefix_( self, prefix: Tuple[str, ...]) -> 'ClassicallyControlledOperation': conditions = [ protocols.with_key_path_prefix(c, prefix) for c in self._conditions ] sub_operation = protocols.with_key_path_prefix(self._sub_operation, prefix) sub_operation = self._sub_operation if sub_operation is NotImplemented else sub_operation return sub_operation.with_classical_controls(*conditions)
def _with_key_path_prefix_(self, prefix: Tuple[str, ...]): new_gate = protocols.with_key_path_prefix(self.gate, prefix) if new_gate is NotImplemented: return NotImplemented if new_gate is self.gate: # As GateOperation is immutable, this can return the original. return self return new_gate.on(*self.qubits)
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() circuit = circuit.transform_qubits(lambda q: self.qubit_map.get(q, q)) if self.repetitions < 0: circuit = circuit**-1 has_measurements = protocols.is_measurement(circuit) if has_measurements: circuit = protocols.with_measurement_key_mapping( circuit, self.measurement_key_map) circuit = protocols.resolve_parameters(circuit, self.param_resolver, recursive=False) if deep: circuit = circuit.map_operations(lambda op: op.mapped_circuit( deep=True) if isinstance(op, CircuitOperation) else op) if self.repetition_ids: if not has_measurements: circuit = circuit * abs(self.repetitions) else: circuit = circuits.Circuit( protocols.with_key_path_prefix(circuit, (rep, )) for rep in self.repetition_ids) if self.parent_path: circuit = protocols.with_key_path_prefix(circuit, self.parent_path) return circuit
def _measurement_key_objs_(self) -> AbstractSet[value.MeasurementKey]: if self._cached_measurement_key_objs is None: circuit_keys = protocols.measurement_key_objs(self.circuit) if self.repetition_ids is not None: circuit_keys = { key.with_key_path_prefix(repetition_id) for repetition_id in self.repetition_ids for key in circuit_keys } circuit_keys = { protocols.with_key_path_prefix(key, self.parent_path) for key in circuit_keys } object.__setattr__( self, '_cached_measurement_key_objs', { protocols.with_measurement_key_mapping( key, self.measurement_key_map) for key in circuit_keys }, ) return self._cached_measurement_key_objs # type: ignore
def _with_key_path_prefix_(self, prefix: Tuple[str, ...]): return MixedUnitaryChannel(mixture=self._mixture, key=protocols.with_key_path_prefix( self._key, prefix))
def _with_key_path_prefix_(self, prefix: Tuple[str, ...]): return Moment( protocols.with_key_path_prefix(op, prefix) if protocols. measurement_keys_touched(op) else op for op in self.operations)
def _with_key_path_prefix_(self, prefix: Tuple[str, ...]): return KrausChannel(kraus_ops=self._kraus_ops, key=protocols.with_key_path_prefix( self._key, prefix))