Skip to content

Commit 80f505e

Browse files
committed
Raphael's feedback on instr.op.definition
1 parent 9cd6f31 commit 80f505e

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

src/qrisp/interface/converter/cirq_converter.py

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import numpy as np
2-
31
from cirq import Circuit, LineQubit
42
from qrisp.circuit import ControlledOperation
53

@@ -96,10 +94,39 @@ def convert_to_cirq(qrisp_circuit):
9694
print(
9795
"Qrisp circuit contains a global phase gate which will be skipped in the Qrisp to Cirq conversion."
9896
)
99-
if op_i in ['rxx', 'rzz', 'xxyy']:
100-
new_circ = instr.op.definition
97+
# the filter is useful for composite gates that do not have a cirq equivalent and have instr.op.definition
98+
cirq_gates_filter = [
99+
"cx",
100+
"cz",
101+
"swap",
102+
"2cx",
103+
"h",
104+
"x",
105+
"y",
106+
"z",
107+
"rx",
108+
"ry",
109+
"rz",
110+
"s",
111+
"t",
112+
"s_dg",
113+
"t_dg",
114+
"measure",
115+
"reset",
116+
"id",
117+
"p",
118+
"sx",
119+
"sx_dg",
120+
]
121+
# create generic 'ncx' keys in the cirq gates filter for the possibility of multicontrolled cx gates
122+
for n in range(3, qrisp_circ_num_qubits + 1):
123+
# start at 3 because 2cx is a Toffoli gate which already exists in Cirq
124+
cirq_gates_filter.append(f"{n}cx")
125+
126+
if (op_i not in cirq_gates_filter) and instr.op.definition:
127+
new_circ = instr.op.definition
101128
cirq_circuit.append(convert_to_cirq(new_circ))
102-
129+
103130
cirq_op_qubits = [qubit_map[q] for q in op_qubits_i]
104131

105132
cirq_gate = qrisp_cirq_ops_dict[op_i]

tests/interface_tests/test_cirq_converter.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
def test_n_qubit_gate_circuit():
1616
"""Verifies the circuit works as expected for a circuit of all single qubit gates."""
1717

18-
# 4 qubit circuit containing all single qubit gates
18+
# 4 qubit circuit containing some single qubit gates
1919
qc_single_qubit_gates = QuantumCircuit(4)
2020
qc_single_qubit_gates.h(0)
2121
qc_single_qubit_gates.x(1)
@@ -52,8 +52,6 @@ def test_n_qubit_gate_circuit():
5252
converted_circ.all_operations()
5353
)
5454

55-
# 4 qubit circuit containing all two qubit gates
56-
5755
# 4 qubit circuit containing all multi-controlled gates
5856
# there is only 1 multicontrolled gate mcx
5957
qc_mcx = QuantumCircuit(10)

0 commit comments

Comments
 (0)