-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_base_decomp.py
44 lines (33 loc) · 1.69 KB
/
test_base_decomp.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
import numpy as np
from pennylane_calculquebec.processing.steps.base_decomposition import CliffordTDecomposition, BaseDecomposition
from pennylane_calculquebec.processing.steps.native_decomposition import MonarqDecomposition
from pennylane_calculquebec.utility.api import instructions
from pennylane_calculquebec.utility.debug import are_tape_same_probs
import pennylane as qml
from pennylane.tape import QuantumTape
import pytest
from functools import reduce
def test_base_decomp_class_empty_gates():
step = BaseDecomposition()
assert len(step.base_gates) == 0
def test_base_decomp_toffoli():
step = CliffordTDecomposition()
ops = [qml.Hadamard(0), qml.Hadamard(1), qml.Toffoli([0, 1, 2])]
tape = QuantumTape(ops=ops, measurements=[qml.probs()])
new_tape = step.execute(tape)
assert all(op.name in step.base_gates for op in new_tape.operations)
assert are_tape_same_probs(tape, new_tape)
def test_base_decomp_unitary():
step = CliffordTDecomposition()
ops = [qml.Hadamard(0), qml.QubitUnitary(np.array([[-1, 1], [1, 1]])/np.sqrt(2), 0)]
tape = QuantumTape(ops=ops, measurements=[qml.probs()])
new_tape = step.execute(tape)
assert all(op.name in step.base_gates for op in new_tape.operations)
assert are_tape_same_probs(tape, new_tape)
def test_base_decomp_cu():
step = CliffordTDecomposition()
ops = [qml.Hadamard(0), qml.Hadamard(1), qml.ControlledQubitUnitary(np.array([[1, 1], [1, -1]])/np.sqrt(2), [0, 1], [2], [0, 1])]
tape = QuantumTape(ops=ops, measurements=[qml.probs()])
new_tape = step.execute(tape)
assert all(op.name in step.base_gates for op in new_tape.operations)
assert are_tape_same_probs(tape, new_tape)