@@ -46,7 +46,7 @@ def random_cv(n: int) -> List[int]:
4646def test_multi_controlled_and_gate (cv : List [int ]):
4747 gate = cirq_ft .And (cv )
4848 r = gate .signature
49- assert r .get_left ( 'ancilla ' ).total_bits () == r .get_left ('control ' ).total_bits () - 2
49+ assert r .get_right ( 'junk ' ).total_bits () == r .get_left ('ctrl ' ).total_bits () - 2
5050 quregs = infra .get_named_qubits (r )
5151 and_op = gate .on_registers (** quregs )
5252 circuit = cirq .Circuit (and_op )
@@ -55,7 +55,7 @@ def test_multi_controlled_and_gate(cv: List[int]):
5555 qubit_order = infra .merge_qubits (gate .signature , ** quregs )
5656
5757 for input_control in input_controls :
58- initial_state = input_control + [0 ] * (r .get_left ( 'ancilla ' ).total_bits () + 1 )
58+ initial_state = input_control + [0 ] * (r .get_right ( 'junk ' ).total_bits () + 1 )
5959 result = cirq .Simulator (dtype = np .complex128 ).simulate (
6060 circuit , initial_state = initial_state , qubit_order = qubit_order
6161 )
@@ -80,64 +80,67 @@ def test_and_gate_diagram():
8080 gate = cirq_ft .And ((1 , 0 , 1 , 0 , 1 , 0 ))
8181 qubit_regs = infra .get_named_qubits (gate .signature )
8282 op = gate .on_registers (** qubit_regs )
83- # Qubit order should be alternating (control, ancilla) pairs.
84- c_and_a = sum (zip (qubit_regs ["control" ][1 :], qubit_regs ["ancilla" ]), ()) + (
85- qubit_regs ["control" ][- 1 ],
83+ ctrl , junk , target = (
84+ qubit_regs ["ctrl" ].flatten (),
85+ qubit_regs ["junk" ].flatten (),
86+ qubit_regs ['target' ].flatten (),
8687 )
87- qubit_order = np .concatenate ([qubit_regs ["control" ][0 :1 ], c_and_a , qubit_regs ["target" ]])
88+ # Qubit order should be alternating (control, ancilla) pairs.
89+ c_and_a = sum (zip (ctrl [1 :], junk ), ()) + (ctrl [- 1 ],)
90+ qubit_order = np .concatenate ([ctrl [0 :1 ], c_and_a , target ])
8891 # Test diagrams.
8992 cirq .testing .assert_has_diagram (
9093 cirq .Circuit (op ),
9194 """
92- control0 : ───@─────
93- │
94- control1 : ───(0)───
95- │
96- ancilla0 : ───Anc───
97- │
98- control2 : ───@─────
99- │
100- ancilla1 : ───Anc───
101- │
102- control3 : ───(0)───
103- │
104- ancilla2 : ───Anc───
105- │
106- control4 : ───@─────
107- │
108- ancilla3 : ───Anc───
109- │
110- control5 : ───(0)───
111- │
112- target: ───── And───
95+ ctrl[0] : ───@─────
96+ │
97+ ctrl[1] : ───(0)───
98+ │
99+ junk[0] : ───Anc───
100+ │
101+ ctrl[2] : ───@─────
102+ │
103+ junk[1] : ───Anc───
104+ │
105+ ctrl[3] : ───(0)───
106+ │
107+ junk[2] : ───Anc───
108+ │
109+ ctrl[4] : ───@─────
110+ │
111+ junk[3] : ───Anc───
112+ │
113+ ctrl[5] : ───(0)───
114+ │
115+ target: ────And───
113116""" ,
114117 qubit_order = qubit_order ,
115118 )
116119 cirq .testing .assert_has_diagram (
117120 cirq .Circuit (op ** - 1 ),
118121 """
119- control0 : ───@──────
120- │
121- control1 : ───(0)────
122- │
123- ancilla0 : ───Anc────
124- │
125- control2 : ───@──────
126- │
127- ancilla1 : ───Anc────
128- │
129- control3 : ───(0)────
130- │
131- ancilla2 : ───Anc────
132- │
133- control4 : ───@──────
134- │
135- ancilla3 : ───Anc────
136- │
137- control5 : ───(0)────
138- │
139- target: ───── And†───
140- """ ,
122+ ctrl[0] : ───@──────
123+ │
124+ ctrl[1] : ───(0)────
125+ │
126+ junk[0] : ───Anc────
127+ │
128+ ctrl[2] : ───@──────
129+ │
130+ junk[1] : ───Anc────
131+ │
132+ ctrl[3] : ───(0)────
133+ │
134+ junk[2] : ───Anc────
135+ │
136+ ctrl[4] : ───@──────
137+ │
138+ junk[3] : ───Anc────
139+ │
140+ ctrl[5] : ───(0)────
141+ │
142+ target: ────And†───
143+ """ ,
141144 qubit_order = qubit_order ,
142145 )
143146 # Test diagram of decomposed 3-qubit and ladder.
@@ -147,28 +150,28 @@ def test_and_gate_diagram():
147150 cirq .testing .assert_has_diagram (
148151 decomposed_circuit ,
149152 """
150- control0 : ───@─────────────────────────────────────────────────────────@──────
151- │ │
152- control1 : ───(0)───────────────────────────────────────────────────────(0)────
153- │ │
154- ancilla0 : ───And───@────────────────────────────────────────────@──────And†───
155- │ │
156- control2 : ─────────@────────────────────────────────────────────@─────────────
157- │ │
158- ancilla1 : ─────────And───@───────────────────────────────@──────And†──────────
159- │ │
160- control3 : ───────────────(0)─────────────────────────────(0)──────────────────
161- │ │
162- ancilla2 : ───────────────And───@──────────────────@──────And†─────────────────
163- │ │
164- control4 : ─────────────────────@──────────────────@───────────────────────────
165- │ │
166- ancilla3 : ─────────────────────And───@─────@──────And†────────────────────────
167- │ │
168- control5 : ───────────────────────────(0)───(0)────────────────────────────────
169- │ │
170- target: ───────────────────────────── And───And†───────────────────────────────
171- """ ,
153+ ctrl[0] : ───@─────────────────────────────────────────────────────────@──────
154+ │ │
155+ ctrl[1] : ───(0)───────────────────────────────────────────────────────(0)────
156+ │ │
157+ junk[0] : ───And───@────────────────────────────────────────────@──────And†───
158+ │ │
159+ ctrl[2] : ─────────@────────────────────────────────────────────@─────────────
160+ │ │
161+ junk[1] : ─────────And───@───────────────────────────────@──────And†──────────
162+ │ │
163+ ctrl[3] : ───────────────(0)─────────────────────────────(0)──────────────────
164+ │ │
165+ junk[2] : ───────────────And───@──────────────────@──────And†─────────────────
166+ │ │
167+ ctrl[4] : ─────────────────────@──────────────────@───────────────────────────
168+ │ │
169+ junk[3] : ─────────────────────And───@─────@──────And†────────────────────────
170+ │ │
171+ ctrl[5] : ───────────────────────────(0)───(0)────────────────────────────────
172+ │ │
173+ target: ────────────────────────────And───And†───────────────────────────────
174+ """ ,
172175 qubit_order = qubit_order ,
173176 )
174177
0 commit comments