-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_verification.py
96 lines (80 loc) · 3.81 KB
/
test_verification.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
'''
Tests for stoqcompiler.verification modules.
'''
from stoqcompiler.verification import Verification
from stoqcompiler.compiler import CompilerResult
from stoqcompiler.unitary import (
Unitary,
UnitaryPrimitive,
ParameterizedUnitaryDefinitions)
qubit_dimension = 2
class TestVerification:
def test_rav(self) -> None:
num_system_qubits = 2
system_dimension = qubit_dimension ** num_system_qubits
unitary_primitives = [
UnitaryPrimitive(ParameterizedUnitaryDefinitions.rotation_xy()),
UnitaryPrimitive(ParameterizedUnitaryDefinitions.xx())]
sequence_length = 10
threshold = 0.5
rav_result = Verification.generate_rav_sequence(
system_dimension, unitary_primitives, sequence_length, threshold)
assert isinstance(rav_result, CompilerResult)
product = rav_result.compiled_sequence.product()
assert product.close_to(
Unitary.identity(system_dimension), threshold), \
product.distance_from(Unitary.identity(system_dimension))
assert rav_result.compiled_sequence.get_qasm()
assert rav_result.compiled_sequence.get_jaqal()
def test_rav_no_inverse(self) -> None:
num_system_qubits = 2
system_dimension = qubit_dimension ** num_system_qubits
unitary_primitives = [
UnitaryPrimitive(ParameterizedUnitaryDefinitions.rotation_xy()),
UnitaryPrimitive(ParameterizedUnitaryDefinitions.xx())]
sequence_length = 10
threshold = 0.0
rav_result = Verification.generate_rav_sequence(
system_dimension, unitary_primitives, sequence_length, threshold)
assert isinstance(rav_result, CompilerResult)
assert rav_result.compiled_sequence.get_length() == sequence_length
assert rav_result.compiled_sequence.get_qasm()
assert rav_result.compiled_sequence.get_jaqal()
def test_layered_rav(self) -> None:
num_system_qubits = 2
system_dimension = qubit_dimension ** num_system_qubits
unitary_primitive_counts = {
UnitaryPrimitive(ParameterizedUnitaryDefinitions.rotation_xy()): 3,
UnitaryPrimitive(ParameterizedUnitaryDefinitions.xx()): 1
}
layer_count = 10
threshold = 0.5
layered_rav_result = Verification.generate_layered_rav_sequence(
system_dimension, unitary_primitive_counts, layer_count, threshold)
assert isinstance(layered_rav_result, CompilerResult)
layer_length = sum(unitary_primitive_counts.values())
assert len(
layered_rav_result.compiled_sequence.get_sequence_entries()
) % layer_length == 0
product = layered_rav_result.compiled_sequence.product()
assert product.close_to(
Unitary.identity(system_dimension), threshold), \
product.distance_from(Unitary.identity(system_dimension))
assert layered_rav_result.compiled_sequence.get_qasm()
assert layered_rav_result.compiled_sequence.get_jaqal()
def test_xeb(self) -> None:
num_system_qubits = 2
system_dimension = qubit_dimension ** num_system_qubits
unitary_primitive_counts = {
UnitaryPrimitive(ParameterizedUnitaryDefinitions.rotation_xy()): 3,
UnitaryPrimitive(ParameterizedUnitaryDefinitions.xx()): 1
}
layer_count = 10
xeb_result = Verification.generate_xeb_sequence(
system_dimension, unitary_primitive_counts, layer_count)
assert isinstance(xeb_result, CompilerResult)
layer_length = sum(unitary_primitive_counts.values())
sequence_length = xeb_result.compiled_sequence.get_length()
assert sequence_length == layer_length * layer_count
assert xeb_result.compiled_sequence.get_qasm()
assert xeb_result.compiled_sequence.get_jaqal()