-
Notifications
You must be signed in to change notification settings - Fork 635
/
Copy pathtest_grouping_utils.py
514 lines (429 loc) · 20.6 KB
/
test_grouping_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
# Copyright 2018-2021 Xanadu Quantum Technologies Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Unit tests for the :mod:`grouping` utility functions in ``grouping/utils.py``.
"""
import pytest
import numpy as np
import pennylane as qml
from pennylane import Identity, PauliX, PauliY, PauliZ, Hadamard, Hermitian, U3
from pennylane.operation import Tensor
from pennylane.wires import Wires
from pennylane.grouping.utils import (
is_pauli_word,
are_identical_pauli_words,
pauli_to_binary,
binary_to_pauli,
pauli_word_to_string,
string_to_pauli_word,
pauli_word_to_matrix,
is_commuting,
is_qwc,
are_pauli_words_qwc,
observables_to_binary_matrix,
qwc_complement_adj_matrix,
)
non_pauli_words = [
PauliX(0) @ Hadamard(1) @ Identity(2),
Hadamard("a"),
U3(0.1, 1, 1, wires="a"),
Hermitian(np.array([[3.2, 1.1 + 0.6j], [1.1 - 0.6j, 3.2]]), wires="a") @ PauliX("b"),
]
class TestGroupingUtils:
"""Basic usage and edge-case tests for the measurement optimization utility functions."""
ops_to_vecs_explicit_wires = [
(PauliX(0) @ PauliY(1) @ PauliZ(2), np.array([1, 1, 0, 0, 1, 1])),
(PauliZ(0) @ PauliY(2), np.array([0, 1, 1, 1])),
(PauliY(1) @ PauliX(2), np.array([1, 1, 1, 0])),
(Identity(0), np.zeros(2)),
]
@pytest.mark.parametrize("op,vec", ops_to_vecs_explicit_wires)
def test_pauli_to_binary_no_wire_map(self, op, vec):
"""Test conversion of Pauli word from operator to binary vector representation when no
``wire_map`` is specified."""
assert (pauli_to_binary(op) == vec).all()
ops_to_vecs_abstract_wires = [
(PauliX("a") @ PauliZ("b") @ Identity("c"), np.array([1, 0, 0, 0, 0, 1, 0, 0])),
(PauliY(6) @ PauliZ("a") @ PauliZ("b"), np.array([0, 0, 0, 1, 1, 1, 0, 1])),
(PauliX("b") @ PauliY("c"), np.array([0, 1, 1, 0, 0, 0, 1, 0])),
(Identity("a") @ Identity(6), np.zeros(8)),
]
@pytest.mark.parametrize("op,vec", ops_to_vecs_abstract_wires)
def test_pauli_to_binary_with_wire_map(self, op, vec):
"""Test conversion of Pauli word from operator to binary vector representation if a
``wire_map`` is specified."""
wire_map = {"a": 0, "b": 1, "c": 2, 6: 3}
assert (pauli_to_binary(op, wire_map=wire_map) == vec).all()
vecs_to_ops_explicit_wires = [
(np.array([1, 0, 1, 0, 0, 1]), PauliX(0) @ PauliY(2)),
(np.array([1, 1, 1, 1, 1, 1]), PauliY(0) @ PauliY(1) @ PauliY(2)),
(np.array([1, 0, 1, 0, 1, 1]), PauliX(0) @ PauliZ(1) @ PauliY(2)),
(np.zeros(6), Identity(0)),
]
@pytest.mark.parametrize("non_pauli_word", non_pauli_words)
def test_pauli_to_binary_non_pauli_word_catch(self, non_pauli_word):
"""Tests TypeError raise for when non Pauli-word Pennylane operations/operators are given
as input to pauli_to_binary."""
assert pytest.raises(TypeError, pauli_to_binary, non_pauli_word)
def test_pauli_to_binary_incompatable_wire_map_n_qubits(self):
"""Tests ValueError raise when n_qubits is not high enough to support the highest wire_map
value."""
pauli_word = PauliX("a") @ PauliY("b") @ PauliZ("c")
wire_map = {"a": 0, "b": 1, "c": 3}
n_qubits = 3
assert pytest.raises(ValueError, pauli_to_binary, pauli_word, n_qubits, wire_map)
@pytest.mark.parametrize("pauli_word,binary_pauli", ops_to_vecs_explicit_wires)
def test_pauli_to_binary_no_check(self, pauli_word, binary_pauli):
"""Tests that pauli_to_binary runs well when pauli words are provided and
check_is_pauli_word is False."""
assert (pauli_to_binary(pauli_word, check_is_pauli_word=False) == binary_pauli).all()
@pytest.mark.parametrize("vec,op", vecs_to_ops_explicit_wires)
def test_binary_to_pauli_no_wire_map(self, vec, op):
"""Test conversion of Pauli in binary vector representation to operator form when no
``wire_map`` is specified."""
assert are_identical_pauli_words(binary_to_pauli(vec), op)
vecs_to_ops_abstract_wires = [
(np.array([1, 0, 1, 0, 0, 1]), PauliX("alice") @ PauliY("ancilla")),
(np.array([1, 1, 1, 1, 1, 1]), PauliY("alice") @ PauliY("bob") @ PauliY("ancilla")),
(np.array([1, 0, 1, 0, 1, 0]), PauliX("alice") @ PauliZ("bob") @ PauliX("ancilla")),
(np.zeros(6), Identity("alice")),
]
@pytest.mark.parametrize("vec,op", vecs_to_ops_abstract_wires)
def test_binary_to_pauli_with_wire_map(self, vec, op):
"""Test conversion of Pauli in binary vector representation to operator form when
``wire_map`` is specified."""
wire_map = {"alice": 0, "bob": 1, "ancilla": 2}
assert are_identical_pauli_words(binary_to_pauli(vec, wire_map=wire_map), op)
binary_vecs_with_invalid_wire_maps = [
([1, 0], {"a": 1}),
([1, 1, 1, 0], {"a": 0}),
([1, 0, 1, 0, 1, 1], {"a": 0, "b": 2, "c": 3}),
([1, 0, 1, 0], {"a": 0, "b": 2}),
]
@pytest.mark.parametrize("binary_vec,wire_map", binary_vecs_with_invalid_wire_maps)
def test_binary_to_pauli_invalid_wire_map(self, binary_vec, wire_map):
"""Tests ValueError raise when wire_map values are not integers 0 to N, for input 2N
dimensional binary vector."""
assert pytest.raises(ValueError, binary_to_pauli, binary_vec, wire_map)
not_binary_symplectic_vecs = [[1, 0, 1, 1, 0], [1], [2, 0, 0, 1], [0.1, 4.3, 2.0, 1.3]]
@pytest.mark.parametrize("not_binary_symplectic", not_binary_symplectic_vecs)
def test_binary_to_pauli_with_illegal_vectors(self, not_binary_symplectic):
"""Test ValueError raise for when non even-dimensional binary vectors are given to
binary_to_pauli."""
assert pytest.raises(ValueError, binary_to_pauli, not_binary_symplectic)
def test_observables_to_binary_matrix(self):
"""Test conversion of list of Pauli word operators to representation as a binary matrix."""
observables = [Identity(1), PauliX(1), PauliZ(0) @ PauliZ(1)]
binary_observables = np.array(
[[0.0, 1.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 1.0], [0.0, 0.0, 1.0]]
).T
assert (observables_to_binary_matrix(observables) == binary_observables).all()
def test_observables_to_binary_matrix_n_qubits_arg(self):
"""Tests if ValueError is raised when specified n_qubits is not large enough to support
the number of distinct wire labels in input observables."""
observables = [Identity(1) @ PauliZ("a"), PauliX(1), PauliZ(0) @ PauliZ(2)]
n_qubits_invalid = 3
assert pytest.raises(
ValueError, observables_to_binary_matrix, observables, n_qubits_invalid
)
def test_is_qwc(self):
"""Determining if two Pauli words are qubit-wise commuting."""
n_qubits = 3
wire_map = {0: 0, "a": 1, "b": 2}
p1_vec = pauli_to_binary(PauliX(0) @ PauliY("a"), wire_map=wire_map)
p2_vec = pauli_to_binary(PauliX(0) @ Identity("a") @ PauliX("b"), wire_map=wire_map)
p3_vec = pauli_to_binary(PauliX(0) @ PauliZ("a") @ Identity("b"), wire_map=wire_map)
identity = pauli_to_binary(Identity("a") @ Identity(0), wire_map=wire_map)
assert is_qwc(p1_vec, p2_vec)
assert not is_qwc(p1_vec, p3_vec)
assert is_qwc(p2_vec, p3_vec)
assert (
is_qwc(p1_vec, identity)
== is_qwc(p2_vec, identity)
== is_qwc(p3_vec, identity)
== is_qwc(identity, identity)
== True
)
obs_lsts = [
([qml.PauliZ(0) @ qml.PauliX(1), qml.PauliY(2), qml.PauliX(1) @ qml.PauliY(2)], True),
([qml.PauliZ(0) @ qml.Identity(1), qml.PauliY(2), qml.PauliX(2) @ qml.PauliY(1)], False),
(
[
qml.PauliZ(0) @ qml.PauliX(1),
qml.PauliY(2),
qml.Identity(1) @ qml.PauliY(2),
qml.Identity(0),
],
True,
), # multi I
([qml.PauliZ(0) @ qml.PauliZ(1), qml.PauliZ(2), qml.PauliX(1) @ qml.PauliY(2)], False),
]
@pytest.mark.parametrize("obs_lst, expected_qwc", obs_lsts)
def test_are_qwc_pauli_words(self, obs_lst, expected_qwc):
"""Given a list of Pauli words test that this function accurately
determines if they are pairwise qubit-wise commuting."""
qwc = are_pauli_words_qwc(obs_lst)
assert qwc == expected_qwc
def test_is_qwc_not_equal_lengths(self):
"""Tests ValueError is raised when input Pauli vectors are not of equal length."""
pauli_vec_1 = [0, 1, 0, 1]
pauli_vec_2 = [1, 1, 0, 1, 0, 1]
assert pytest.raises(ValueError, is_qwc, pauli_vec_1, pauli_vec_2)
def test_is_qwc_not_even_lengths(self):
"""Tests ValueError is raised when input Pauli vectors are not of even length."""
pauli_vec_1 = [1, 0, 1]
pauli_vec_2 = [1, 1, 1]
assert pytest.raises(ValueError, is_qwc, pauli_vec_1, pauli_vec_2)
def test_is_qwc_not_binary_vectors(self):
"""Tests ValueError is raised when input Pauli vectors do not have binary
components."""
pauli_vec_1 = [1, 3.2, 1, 1 + 2j]
pauli_vec_2 = [1, 0, 0, 0]
assert pytest.raises(ValueError, is_qwc, pauli_vec_1, pauli_vec_2)
def test_is_pauli_word(self):
"""Test for determining whether input ``Observable`` instance is a Pauli word."""
observable_1 = PauliX(0)
observable_2 = PauliZ(1) @ PauliX(2) @ PauliZ(4)
observable_3 = PauliX(1) @ Hadamard(4)
observable_4 = Hadamard(0)
assert is_pauli_word(observable_1)
assert is_pauli_word(observable_2)
assert not is_pauli_word(observable_3)
assert not is_pauli_word(observable_4)
def test_is_pauli_word_non_observable(self):
"""Test that non-observables are not Pauli Words."""
class DummyOp(qml.operation.Operator):
num_wires = 1
assert not is_pauli_word(DummyOp(1))
def test_are_identical_pauli_words(self):
"""Tests for determining if two Pauli words have the same ``wires`` and ``name`` attributes."""
pauli_word_1 = Tensor(PauliX(0))
pauli_word_2 = PauliX(0)
assert are_identical_pauli_words(pauli_word_1, pauli_word_2)
assert are_identical_pauli_words(pauli_word_2, pauli_word_1)
pauli_word_1 = PauliX(0) @ PauliY(1)
pauli_word_2 = PauliY(1) @ PauliX(0)
pauli_word_3 = Tensor(PauliX(0), PauliY(1))
pauli_word_4 = PauliX(1) @ PauliZ(2)
assert are_identical_pauli_words(pauli_word_1, pauli_word_2)
assert are_identical_pauli_words(pauli_word_1, pauli_word_3)
assert not are_identical_pauli_words(pauli_word_1, pauli_word_4)
assert not are_identical_pauli_words(pauli_word_3, pauli_word_4)
@pytest.mark.parametrize("non_pauli_word", non_pauli_words)
def test_are_identical_pauli_words_non_pauli_word_catch(self, non_pauli_word):
"""Tests TypeError raise for when non-Pauli word Pennylane operators/operations are given
as input to are_identical_pauli_words."""
with pytest.raises(TypeError):
are_identical_pauli_words(non_pauli_word, PauliZ(0) @ PauliZ(1))
with pytest.raises(TypeError):
are_identical_pauli_words(non_pauli_word, PauliZ(0) @ PauliZ(1))
with pytest.raises(TypeError):
are_identical_pauli_words(PauliX("a") @ Identity("b"), non_pauli_word)
with pytest.raises(TypeError):
are_identical_pauli_words(non_pauli_word, non_pauli_word)
def test_qwc_complement_adj_matrix(self):
"""Tests that the ``qwc_complement_adj_matrix`` function returns the correct
adjacency matrix."""
binary_observables = np.array(
[
[1.0, 0.0, 1.0, 0.0, 0.0, 1.0],
[0.0, 1.0, 1.0, 1.0, 0.0, 1.0],
[0.0, 0.0, 0.0, 1.0, 0.0, 0.0],
]
)
adj = qwc_complement_adj_matrix(binary_observables)
expected = np.array([[0.0, 1.0, 1.0], [1.0, 0.0, 0.0], [1.0, 0.0, 0.0]])
assert np.all(adj == expected)
binary_obs_list = list(binary_observables)
adj = qwc_complement_adj_matrix(binary_obs_list)
assert np.all(adj == expected)
binary_obs_tuple = tuple(binary_observables)
adj = qwc_complement_adj_matrix(binary_obs_tuple)
assert np.all(adj == expected)
def test_qwc_complement_adj_matrix_exception(self):
"""Tests that the ``qwc_complement_adj_matrix`` function raises an exception if
the matrix is not binary."""
not_binary_observables = np.array(
[
[1.1, 0.5, 1.0, 0.0, 0.0, 1.0],
[0.0, 1.3, 1.0, 1.0, 0.0, 1.0],
[2.2, 0.0, 0.0, 1.0, 0.0, 0.0],
]
)
with pytest.raises(ValueError, match="Expected a binary array, instead got"):
qwc_complement_adj_matrix(not_binary_observables)
@pytest.mark.parametrize(
"pauli_word,wire_map,expected_string",
[
(PauliX(0), {0: 0}, "X"),
(Identity(0), {0: 0}, "I"),
(PauliZ(0) @ PauliY(1), {0: 0, 1: 1}, "ZY"),
(PauliX(1), {0: 0, 1: 1}, "IX"),
(PauliX(1), None, "X"),
(PauliX(1), {1: 0, 0: 1}, "XI"),
(PauliZ("a") @ PauliY("b") @ PauliZ("d"), {"a": 0, "b": 1, "c": 2, "d": 3}, "ZYIZ"),
(PauliZ("a") @ PauliY("b") @ PauliZ("d"), None, "ZYZ"),
(PauliX("a") @ PauliY("b") @ PauliZ("d"), {"d": 0, "c": 1, "b": 2, "a": 3}, "ZIYX"),
],
)
def test_pauli_word_to_string(self, pauli_word, wire_map, expected_string):
"""Test that Pauli words are correctly converted into strings."""
obtained_string = pauli_word_to_string(pauli_word, wire_map)
assert obtained_string == expected_string
@pytest.mark.parametrize("non_pauli_word", non_pauli_words)
def test_pauli_word_to_string_invalid_input(self, non_pauli_word):
"""Ensure invalid inputs are handled properly when converting Pauli words to strings."""
with pytest.raises(TypeError):
pauli_word_to_string(non_pauli_word)
@pytest.mark.parametrize(
"pauli_string,wire_map,expected_pauli",
[
("I", {"a": 0}, Identity("a")),
("X", {0: 0}, PauliX(0)),
("XI", {1: 0, 0: 1}, PauliX(1)),
("II", {0: 0, 1: 1}, Identity(0)),
("ZYIZ", {"a": 0, "b": 1, "c": 2, "d": 3}, PauliZ("a") @ PauliY("b") @ PauliZ("d")),
("ZYZ", None, PauliZ(0) @ PauliY(1) @ PauliZ(2)),
("ZIYX", {"d": 0, "c": 1, "b": 2, "a": 3}, PauliZ("d") @ PauliY("b") @ PauliX("a")),
],
)
def test_string_to_pauli_word(self, pauli_string, wire_map, expected_pauli):
"""Test that valid strings are correctly converted into Pauli words."""
obtained_pauli = string_to_pauli_word(pauli_string, wire_map)
assert obtained_pauli.compare(expected_pauli)
@pytest.mark.parametrize(
"non_pauli_string,wire_map,error_type,error_message",
[
(Identity("a"), None, TypeError, "must be string"),
("XAYZ", None, ValueError, "Invalid characters encountered"),
("XYYZ", {0: 0, 1: 1, 2: 2}, ValueError, "must have the same length"),
],
)
def test_string_to_pauli_word_invalid_input(
self, non_pauli_string, wire_map, error_type, error_message
):
"""Ensure invalid inputs are handled properly when converting strings to Pauli words."""
with pytest.raises(error_type, match=error_message):
string_to_pauli_word(non_pauli_string, wire_map)
@pytest.mark.parametrize(
"pauli_word,wire_map,expected_matrix",
[
(PauliX(0), {0: 0}, PauliX(0).matrix()),
(Identity(0), {0: 0}, np.eye(2)),
(
PauliZ(0) @ PauliY(1),
{0: 0, 1: 1},
np.array([[0, -1j, 0, 0], [1j, 0, 0, 0], [0, 0, 0, 1j], [0, 0, -1j, 0]]),
),
(
PauliY(1) @ PauliZ(0),
{0: 0, 1: 1},
np.array([[0, -1j, 0, 0], [1j, 0, 0, 0], [0, 0, 0, 1j], [0, 0, -1j, 0]]),
),
(
PauliY(1) @ PauliZ(0),
{1: 0, 0: 1},
np.array([[0, 0, -1j, 0], [0, 0, 0, 1j], [1j, 0, 0, 0], [0, -1j, 0, 0]]),
),
(Identity(0), {0: 0, 1: 1}, np.eye(4)),
(PauliX(2), None, PauliX(2).matrix()),
(
PauliX(2),
{0: 0, 1: 1, 2: 2},
np.array(
[
[0, 1, 0, 0, 0, 0, 0, 0],
[1, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 1, 0, 0],
[0, 0, 0, 0, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 1],
[0, 0, 0, 0, 0, 0, 1, 0],
]
),
),
(
PauliZ("a") @ PauliX(2),
{"a": 0, 1: 1, 2: 2},
np.array(
[
[0, 1, 0, 0, 0, 0, 0, 0],
[1, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, -1, 0, 0],
[0, 0, 0, 0, -1, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, -1],
[0, 0, 0, 0, 0, 0, -1, 0],
]
),
),
(
PauliX(2) @ PauliZ("a"),
{"a": 0, 1: 1, 2: 2},
np.array(
[
[0, 1, 0, 0, 0, 0, 0, 0],
[1, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, -1, 0, 0],
[0, 0, 0, 0, -1, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, -1],
[0, 0, 0, 0, 0, 0, -1, 0],
]
),
),
],
)
def test_pauli_word_to_matrix(self, pauli_word, wire_map, expected_matrix):
"""Test that Pauli words are correctly converted into matrices."""
obtained_matrix = pauli_word_to_matrix(pauli_word, wire_map)
assert np.allclose(obtained_matrix, expected_matrix)
@pytest.mark.parametrize("non_pauli_word", non_pauli_words)
def test_pauli_word_to_matrix_invalid_input(self, non_pauli_word):
"""Ensure invalid inputs are handled properly when converting Pauli words to matrices."""
with pytest.raises(TypeError):
pauli_word_to_matrix(non_pauli_word)
@pytest.mark.parametrize(
"pauli_word_1,pauli_word_2,wire_map,commute_status",
[
(Identity(0), PauliZ(0), {0: 0}, True),
(PauliY(0), PauliZ(0), {0: 0}, False),
(PauliX(0), PauliX(1), {0: 0, 1: 1}, True),
(PauliY("x"), PauliX("y"), None, True),
(
PauliZ("a") @ PauliY("b") @ PauliZ("d"),
PauliX("a") @ PauliZ("c") @ PauliY("d"),
{"a": 0, "b": 1, "c": 2, "d": 3},
True,
),
(
PauliX("a") @ PauliY("b") @ PauliZ("d"),
PauliX("a") @ PauliZ("c") @ PauliY("d"),
{"a": 0, "b": 1, "c": 2, "d": 3},
False,
),
],
)
def test_is_commuting(self, pauli_word_1, pauli_word_2, wire_map, commute_status):
"""Test that (non)-commuting Pauli words are correctly identified."""
do_they_commute = is_commuting(pauli_word_1, pauli_word_2, wire_map=wire_map)
assert do_they_commute == commute_status
@pytest.mark.parametrize(
"pauli_word_1,pauli_word_2",
[(non_pauli_words[0], PauliX(0) @ PauliY(2)), (PauliX(0) @ PauliY(2), non_pauli_words[0])],
)
def test_is_commuting_invalid_input(self, pauli_word_1, pauli_word_2):
"""Ensure invalid inputs are handled properly when determining commutativity."""
with pytest.raises(TypeError):
is_commuting(pauli_word_1, pauli_word_2)