Skip to content

Commit

Permalink
refactor: made nmeasurements and moements properties
Browse files Browse the repository at this point in the history
  • Loading branch information
BrunoLiegiBastonLiegi committed Mar 11, 2024
1 parent 67bd842 commit 19e884c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/qibo/models/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,11 @@ def from_fused(self):
queue.append(gate.gates[0])
return queue

@property
def nmeasurements(self):
return len([1 for gate in self if isinstance(gate, gates.M)])

@property
def moments(self):
moments = [self.nqubits * [None]]
moment_index = self.nqubits * [0]
Expand Down Expand Up @@ -658,7 +660,7 @@ def add(self, gate):
self.queue.append(gate)
if gate.register_name is None:
# add default register name
nreg = self.queue.nmeasurements() - 1
nreg = self.queue.nmeasurements - 1
gate.register_name = f"register{nreg}"
else:
registers = self.measurement_tuples
Expand Down Expand Up @@ -712,7 +714,7 @@ def ngates(self) -> int:
def depth(self) -> int:
"""Circuit depth if each gate is placed at the earliest possible
position."""
return len(self.queue.moments())
return len(self.queue.moments)

@property
def gate_types(self) -> collections.Counter:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_models_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_queue_class():
]
for g in gatelist:
queue.append(g)
assert queue.moments() == [
assert queue.moments == [
[gatelist[0], gatelist[1], gatelist[3], gatelist[5]],
[gatelist[2], gatelist[4], gatelist[4], None],
]
Expand Down

0 comments on commit 19e884c

Please sign in to comment.