From c307e4a216251e7552f4d4968c21bae68531145d Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Fri, 10 Jan 2025 13:59:15 -0800 Subject: [PATCH] map qubits --- .../experiments/random_quantum_circuit_generation.py | 2 +- cirq-core/cirq/experiments/xeb_sampling.py | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/cirq-core/cirq/experiments/random_quantum_circuit_generation.py b/cirq-core/cirq/experiments/random_quantum_circuit_generation.py index 72b9dd50088..4d9ccd1b174 100644 --- a/cirq-core/cirq/experiments/random_quantum_circuit_generation.py +++ b/cirq-core/cirq/experiments/random_quantum_circuit_generation.py @@ -342,7 +342,7 @@ def generate_library_of_2q_circuits_for_circuit_op( else: op = circuits.CircuitOperation(circuit_or_op.freeze()).with_tags(*tags) - two_qubit_op_factory = lambda a, b, _: op.with_qubits(a, b) + two_qubit_op_factory = lambda a, b, _: op.with_qubits(a, b).mapped_op() return _generate_library_of_2q_circuits( n_library_circuits=n_library_circuits, two_qubit_op_factory=two_qubit_op_factory, diff --git a/cirq-core/cirq/experiments/xeb_sampling.py b/cirq-core/cirq/experiments/xeb_sampling.py index 44dc31197f5..e4f528ecaa5 100644 --- a/cirq-core/cirq/experiments/xeb_sampling.py +++ b/cirq-core/cirq/experiments/xeb_sampling.py @@ -34,7 +34,7 @@ import tqdm from cirq import ops, devices, value, protocols -from cirq.circuits import Circuit, Moment +from cirq.circuits import Circuit, Moment, CircuitOperation from cirq.experiments.random_quantum_circuit_generation import CircuitLibraryCombination if TYPE_CHECKING: @@ -184,7 +184,9 @@ def _get_combinations_by_layer_for_isolated_xeb( """ q0, q1 = _verify_and_get_two_qubits_from_circuits(circuits) circuits = [ - circuit.transform_qubits(lambda q: {q0: devices.LineQubit(0), q1: devices.LineQubit(1)}[q]) + circuit.transform_qubits( + lambda q: {q0: devices.LineQubit(0), q1: devices.LineQubit(1)}[q] + ).map_operations(lambda op: op.mapped_op() if isinstance(op, CircuitOperation) else op) for circuit in circuits ] return [ @@ -215,7 +217,11 @@ def _zip_circuits( for combination_i, combination in enumerate(layer_combinations.combinations): wide_circuit = Circuit.zip( *( - circuits[i].transform_qubits(lambda q: pair[q.x]) + circuits[i] + .transform_qubits(lambda q: pair[q.x]) + .map_operations( + lambda op: op.mapped_op() if isinstance(op, CircuitOperation) else op + ) for i, pair in zip(combination, layer_combinations.pairs) ) )