Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix circuit plot error for gates with classical controls when reverse_states=False #221

Merged
merged 2 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/qutip_qip/circuit/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,9 @@ def latex_code(self):
gate.classical_controls
and (n - self.N) in gate.classical_controls
):
control_tag = n - gate.targets[0]
control_tag = (-1 if self.reverse_states else 1) * (
gate.targets[0] - n
)
col.append(r" \ctrl{%d} " % control_tag)

elif not gate.controls and not gate.targets:
Expand Down
19 changes: 19 additions & 0 deletions tests/test_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,25 @@ def test_latex_code_teleportation_circuit(self):
"",
])

def test_latex_code_classical_controls(self):
qc = QubitCircuit(1, num_cbits=1, reverse_states=True)
qc.add_gate("X", targets=0, classical_controls=[0])
latex = qc.latex_code()
assert latex == self._latex_template % "\n".join([
r" & & \ctrl{1} & \qw \\ ",
r" & & \gate{X} & \qw \\ ",
"",
])

qc = QubitCircuit(1, num_cbits=1, reverse_states=False)
qc.add_gate("X", targets=0, classical_controls=[0])
latex = qc.latex_code()
assert latex == self._latex_template % "\n".join([
r" & & \gate{X} & \qw \\ ",
r" & & \ctrl{-1} & \qw \\ ",
"",
])

H = Qobj([[1/np.sqrt(2), 1/np.sqrt(2)], [1/np.sqrt(2), -1/np.sqrt(2)]])
H_zyz_gates = _ZYZ_rotation(H)
H_zyz_quantum_circuit = QubitCircuit(1)
Expand Down