Skip to content

Commit

Permalink
Merge pull request #168 from BoxiLi/chain_strucuture_bug
Browse files Browse the repository at this point in the history
Fix bugs in to_chain_structure
  • Loading branch information
BoxiLi committed Apr 15, 2023
2 parents 363eb9d + 1d23b93 commit 72aad5d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
14 changes: 6 additions & 8 deletions src/qutip_qip/transpiler/chain.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from copy import deepcopy
from ..circuit import QubitCircuit


Expand Down Expand Up @@ -27,7 +28,8 @@ def to_chain_structure(qc, setup="linear"):
# FIXME This huge block has been here for a long time.
# It could be moved to the new compiler section and carefully
# splitted into smaller peaces.
qc_t = QubitCircuit(qc.N, qc.reverse_states)
qc_t = deepcopy(qc)
qc_t.gates = []
swap_gates = [
"SWAP",
"ISWAP",
Expand Down Expand Up @@ -263,12 +265,8 @@ def to_chain_structure(qc, setup="linear"):
j = j + 1

else:
qc_t.add_gate(
gate.name,
gate.targets,
gate.controls,
gate.arg_value,
gate.arg_label,
)
# This gate can be general quantum operations
# such as measurement or global phase.
qc_t.add_gate(gate)

return qc_t
13 changes: 12 additions & 1 deletion tests/test_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from qutip_qip.operations import (
Gate, gates, Measurement, gate_sequence_product
)

from qutip_qip.transpiler import to_chain_structure
from qutip_qip.decompose.decompose_single_qubit_gate import _ZYZ_rotation

import qutip as qp
Expand Down Expand Up @@ -763,3 +763,14 @@ def test_deprecation_warning(self):
with pytest.warns(DeprecationWarning):
from qutip_qip.circuit import Gate, Measurement
Gate("X", 0)

def test_circuit_chain_structure(self):
"""
Test if the transpiler correctly inherit the properties of a circuit.
"""
qc = QubitCircuit(3, reverse_states=True)
qc.add_gate("CNOT", 2, 0)
qc2 = to_chain_structure(qc)

assert qc2.reverse_states is True
assert qc2.input_states == [None] * 3

0 comments on commit 72aad5d

Please sign in to comment.