test some adjacent toffoli gates

This commit is contained in:
Daniel Tsvetkov 2020-03-28 22:24:47 +01:00
parent 60a11f143e
commit b98ffcb396
1 changed files with 7 additions and 10 deletions

17
lib.py
View File

@ -650,6 +650,7 @@ class UnitaryOperator(LinearTransformation, UnitaryMatrix):
extended_m[1].append(I)
else:
this_partial = self.partials[next_partial]
# TODO: This works only with C_partial :(((
if this_partial == C_partial:
extended_m[0].append(s("|0><0|"))
extended_m[1].append(s("|1><1|"))
@ -1002,9 +1003,12 @@ def test_partials():
assert CNOT.on(s("|1000>"), which_qbit=[0, 3]) == s("|1001>")
# test Toffoli gate
# assert TOFF.on(s("|000>")) == s("|000>")
# assert TOFF.on(s("|100>")) == s("|100>")
# assert TOFF.on(s("|110>")) == s("|111>")
assert TOFF.on(s("|000>")) == s("|000>")
assert TOFF.on(s("|100>")) == s("|100>")
assert TOFF.on(s("|110>")) == s("|111>")
assert TOFF.on(s("|111>")) == s("|110>")
# TODO: This doesn't work :(((
# assert TOFF.on(s("|1100>"), which_qbit=[0, 1, 3]) == s("|1101>")
@ -1275,13 +1279,6 @@ class QuantumCircuit(object):
self.add_row(row_data)
def compose_quantum_state(self, step):
partials = [op for op in step if isinstance(op, PartialQubit)]
# TODO: No more than 1 TwoQubitGate **OR** UnitaryOperator can be
# used in a step
for partial in partials:
two_qubit_op = partial.operator
two_qubit_op.verify_step()
return two_qubit_op.compose(step)
return reduce((lambda x, y: x * y), step)
def step(self):