@@ -46,7 +46,7 @@ def random_cv(n: int) -> List[int]:
46
46
def test_multi_controlled_and_gate (cv : List [int ]):
47
47
gate = cirq_ft .And (cv )
48
48
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
50
50
quregs = infra .get_named_qubits (r )
51
51
and_op = gate .on_registers (** quregs )
52
52
circuit = cirq .Circuit (and_op )
@@ -55,7 +55,7 @@ def test_multi_controlled_and_gate(cv: List[int]):
55
55
qubit_order = infra .merge_qubits (gate .signature , ** quregs )
56
56
57
57
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 )
59
59
result = cirq .Simulator (dtype = np .complex128 ).simulate (
60
60
circuit , initial_state = initial_state , qubit_order = qubit_order
61
61
)
@@ -80,64 +80,67 @@ def test_and_gate_diagram():
80
80
gate = cirq_ft .And ((1 , 0 , 1 , 0 , 1 , 0 ))
81
81
qubit_regs = infra .get_named_qubits (gate .signature )
82
82
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 (),
86
87
)
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 ])
88
91
# Test diagrams.
89
92
cirq .testing .assert_has_diagram (
90
93
cirq .Circuit (op ),
91
94
"""
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───
113
116
""" ,
114
117
qubit_order = qubit_order ,
115
118
)
116
119
cirq .testing .assert_has_diagram (
117
120
cirq .Circuit (op ** - 1 ),
118
121
"""
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
+ """ ,
141
144
qubit_order = qubit_order ,
142
145
)
143
146
# Test diagram of decomposed 3-qubit and ladder.
@@ -147,28 +150,28 @@ def test_and_gate_diagram():
147
150
cirq .testing .assert_has_diagram (
148
151
decomposed_circuit ,
149
152
"""
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
+ """ ,
172
175
qubit_order = qubit_order ,
173
176
)
174
177
0 commit comments