From 56b1168e9f6df773fd66c8309f8e04a38309433d Mon Sep 17 00:00:00 2001 From: BrunoLiegiBastonLiegi Date: Tue, 2 Apr 2024 17:12:31 +0200 Subject: [PATCH] fix: some cleaning --- src/qibo/models/circuit.py | 10 ---------- src/qibo/result.py | 21 ++++----------------- tests/test_result.py | 13 ------------- 3 files changed, 4 insertions(+), 40 deletions(-) diff --git a/src/qibo/models/circuit.py b/src/qibo/models/circuit.py index b87af1bbbf..67ec3a670b 100644 --- a/src/qibo/models/circuit.py +++ b/src/qibo/models/circuit.py @@ -673,16 +673,6 @@ def add(self, gate): raise_error( KeyError, f"Register {name} already exists in circuit." ) - """ - registers = self.measurement_tuples - for register, qubits in registers.items(): - intersection = set(qubits).intersection(set(gate.target_qubits)) - if len(intersection) > 0: - raise_error( - KeyError, - f"Qubits {tuple(intersection)} already measured in register `{register}`.", - ) - """ gate.result.circuit = self if gate.collapse: diff --git a/src/qibo/result.py b/src/qibo/result.py index 4936af18b5..934f156e39 100644 --- a/src/qibo/result.py +++ b/src/qibo/result.py @@ -177,7 +177,6 @@ def __init__( self.nshots = nshots self._measurement_gate = None - self._measurement_registers = None self._probs = probabilities self._samples = samples self._frequencies = None @@ -256,8 +255,8 @@ def frequencies(self, binary: bool = True, registers: bool = False): if registers: return { - register: gate.result.frequencies(binary) - for register, gate in self._measurement_registers + gate.register_name: gate.result.frequencies(binary) + for gate in self.measurements } if binary: @@ -363,8 +362,8 @@ def samples(self, binary: bool = True, registers: bool = False): if registers: return { - register: gate.result.samples(binary) - for register, gate in self._measurement_registers + gate.register_name: gate.result.samples(binary) + for gate in self.measurements } if binary: @@ -389,18 +388,6 @@ def measurement_gate(self): return self._measurement_gate - def measurement_registers(self): - if self._measurement_registers is None: - registers = {} - for gate in self.measurements: - if gate.register_name in registers: - registers[gate.register_name].add(gate) - else: - registers[gate.register_name] = gate - self._measurement_registers = registers - - return self._measurement_registers - def apply_bitflips(self, p0: float, p1: Optional[float] = None): """Apply bitflips to the measurements with probabilities `p0` and `p1` diff --git a/tests/test_result.py b/tests/test_result.py index 0d2aa8b131..53d274d896 100644 --- a/tests/test_result.py +++ b/tests/test_result.py @@ -40,19 +40,6 @@ def test_measurementoutcomes_probabilities(backend, qubits): backend.assert_allclose(result.probabilities(qubits), probabilities, atol=1e-1) -def test_measurementoutcomes_measurement_registers(backend): - c = Circuit(3) - c.add(gates.H(0)) - c_copy = c.copy() - c.add(gates.M(0, register_name="m0")) - c.add(gates.M(2, register_name="m0")) - c_copy.add(gates.M(0, 2, register_name="m0")) - res = backend.execute_circuit(c) - res_copy = backend.execute_circuit(c_copy) - samples = res.samples(registers=True) - samples_copy = res_copy.samples(registers=True) - - def test_circuit_result_error(backend): c = models.Circuit(1) state = np.array([1, 0])