Skip to content

Commit

Permalink
fix: some cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
BrunoLiegiBastonLiegi committed Apr 2, 2024
1 parent bcaebac commit 56b1168
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 40 deletions.
10 changes: 0 additions & 10 deletions src/qibo/models/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
21 changes: 4 additions & 17 deletions src/qibo/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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`
Expand Down
13 changes: 0 additions & 13 deletions tests/test_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down

0 comments on commit 56b1168

Please sign in to comment.