Skip to content

Commit

Permalink
feat: added test for moments with callback gates
Browse files Browse the repository at this point in the history
  • Loading branch information
BrunoLiegiBastonLiegi committed Mar 11, 2024
1 parent 19e884c commit 39ba5d4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/qibo/models/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def moments(self):
moments = [self.nqubits * [None]]
moment_index = self.nqubits * [0]
for gate in self:
if gate.qubits:
if not isinstance(gate, gates.CallbackGate):
qubits = gate.qubits
else: # special gate acting on all qubits
qubits = tuple(range(self.nqubits))
Expand Down
4 changes: 4 additions & 0 deletions tests/test_models_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ def test_parametrizedgates_class():


def test_queue_class():
from qibo.callbacks import EntanglementEntropy
from qibo.models.circuit import _Queue

entropy = EntanglementEntropy([0])
queue = _Queue(4)
gatelist = [
gates.H(0),
Expand All @@ -29,12 +31,14 @@ def test_queue_class():
gates.H(2),
gates.CNOT(1, 2),
gates.Y(3),
gates.CallbackGate(entropy),
]
for g in gatelist:
queue.append(g)
assert queue.moments == [
[gatelist[0], gatelist[1], gatelist[3], gatelist[5]],
[gatelist[2], gatelist[4], gatelist[4], None],
[gatelist[6] for _ in range(4)],
]


Expand Down

0 comments on commit 39ba5d4

Please sign in to comment.