|
14 | 14 |
|
15 | 15 | """Tests for `parity_gates.py`.""" |
16 | 16 |
|
| 17 | +from typing import List |
| 18 | + |
17 | 19 | import numpy as np |
18 | 20 | import pytest |
19 | 21 | import sympy |
@@ -348,3 +350,60 @@ def test_clifford_protocols(gate_cls: type[cirq.EigenGate], exponent: float, is_ |
348 | 350 | else: |
349 | 351 | assert not cirq.has_stabilizer_effect(gate) |
350 | 352 | assert gate._decompose_into_clifford_with_qubits_(cirq.LineQubit.range(2)) is NotImplemented |
| 353 | + |
| 354 | + |
| 355 | +@pytest.mark.parametrize( |
| 356 | + 'gate, expected_decomposition', |
| 357 | + [ |
| 358 | + ( |
| 359 | + cirq.XXPowGate(), |
| 360 | + [ |
| 361 | + (cirq.Y**-0.5).on(cirq.LineQubit(0)), |
| 362 | + (cirq.Y**-0.5).on(cirq.LineQubit(1)), |
| 363 | + cirq.Z(cirq.LineQubit(0)), |
| 364 | + cirq.Z(cirq.LineQubit(1)), |
| 365 | + (cirq.CZ**-2.0).on(cirq.LineQubit(0), cirq.LineQubit(1)), |
| 366 | + (cirq.Y**0.5).on(cirq.LineQubit(0)), |
| 367 | + (cirq.Y**0.5).on(cirq.LineQubit(1)), |
| 368 | + ], |
| 369 | + ), |
| 370 | + ( |
| 371 | + cirq.YYPowGate(), |
| 372 | + [ |
| 373 | + (cirq.X**0.5).on(cirq.LineQubit(0)), |
| 374 | + (cirq.X**0.5).on(cirq.LineQubit(1)), |
| 375 | + cirq.Z(cirq.LineQubit(0)), |
| 376 | + cirq.Z(cirq.LineQubit(1)), |
| 377 | + (cirq.CZ**-2.0).on(cirq.LineQubit(0), cirq.LineQubit(1)), |
| 378 | + (cirq.X**-0.5).on(cirq.LineQubit(0)), |
| 379 | + (cirq.X**-0.5).on(cirq.LineQubit(1)), |
| 380 | + ], |
| 381 | + ), |
| 382 | + ( |
| 383 | + cirq.ZZPowGate(), |
| 384 | + [ |
| 385 | + cirq.Z(cirq.LineQubit(0)), |
| 386 | + cirq.Z(cirq.LineQubit(1)), |
| 387 | + (cirq.CZ**-2.0).on(cirq.LineQubit(0), cirq.LineQubit(1)), |
| 388 | + ], |
| 389 | + ), |
| 390 | + ( |
| 391 | + cirq.MSGate(rads=0), |
| 392 | + [ |
| 393 | + (cirq.Y**-0.5).on(cirq.LineQubit(0)), |
| 394 | + (cirq.Y**-0.5).on(cirq.LineQubit(1)), |
| 395 | + (cirq.Z**0.0).on(cirq.LineQubit(0)), |
| 396 | + (cirq.Z**0.0).on(cirq.LineQubit(1)), |
| 397 | + cirq.CZPowGate(exponent=-0.0, global_shift=0.25).on( |
| 398 | + cirq.LineQubit(0), cirq.LineQubit(1) |
| 399 | + ), |
| 400 | + (cirq.Y**0.5).on(cirq.LineQubit(0)), |
| 401 | + (cirq.Y**0.5).on(cirq.LineQubit(1)), |
| 402 | + ], |
| 403 | + ), |
| 404 | + ], |
| 405 | +) |
| 406 | +def test_gate_decomposition(gate: cirq.Gate, expected_decomposition: List[cirq.Gate]): |
| 407 | + qubits = cirq.LineQubit.range(gate.num_qubits()) |
| 408 | + dec = cirq.decompose(gate.on(*qubits)) |
| 409 | + assert [op for op in dec] == expected_decomposition |
0 commit comments