-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathtest_parsers.py
143 lines (115 loc) · 3.84 KB
/
test_parsers.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
import numpy as np
import pytest
from c3.c3objs import Quantity
from c3.libraries.envelopes import envelopes
from c3.signal.gates import Instruction
from c3.signal.pulse import Envelope, Carrier
from c3.model import Model
from c3.generator.generator import Generator
from c3.parametermap import ParameterMap
from c3.experiment import Experiment as Exp
model = Model()
model.read_config("test/test_model.cfg")
gen = Generator()
gen.read_config("test/generator.cfg")
pmap = ParameterMap(model=model, generator=gen)
pmap.read_config("test/instructions.cfg")
@pytest.mark.unit
def test_name_collision() -> None:
broken_model = Model()
with pytest.raises(KeyError):
broken_model.read_config("test/test_model_breaking.cfg")
@pytest.mark.unit
def test_subsystems() -> None:
assert list(model.subsystems.keys()) == [
"Q1",
"Q2",
"Q3",
]
@pytest.mark.unit
def test_couplings() -> None:
assert list(model.couplings.keys()) == ["Q1-Q2", "d1", "d2"]
@pytest.mark.unit
def test_tasks() -> None:
"""Task creation is tested separately in the absence of Von Neumann eqn"""
model = Model()
model.read_config("test/test_model_spam.cfg")
pmap = ParameterMap(model=model, generator=gen)
pmap.read_config("test/instructions.cfg")
assert list(model.tasks.keys()) == ["init_ground", "conf_matrix", "meas_rescale"]
@pytest.mark.unit
def test_q3_freq() -> None:
assert str(model.subsystems["Q3"].params["freq"]) == "5.000 GHz 2pi "
@pytest.mark.unit
def test_instructions() -> None:
assert list(pmap.instructions.keys()) == ["rx90p", "ry90p", "rx90m", "ry90m"]
@pytest.mark.integration
def test_signal_generation() -> None:
t_final = 7e-9 # Time for single qubit gates
sideband = 50e6 * 2 * np.pi
gauss_params_single = {
"amp": Quantity(value=0.5, min_val=0.4, max_val=0.6, unit="V"),
"t_final": Quantity(
value=t_final, min_val=0.5 * t_final, max_val=1.5 * t_final, unit="s"
),
"sigma": Quantity(
value=t_final / 4, min_val=t_final / 8, max_val=t_final / 2, unit="s"
),
"xy_angle": Quantity(
value=0.0, min_val=-0.5 * np.pi, max_val=2.5 * np.pi, unit="rad"
),
"freq_offset": Quantity(
value=-sideband - 3e6 * 2 * np.pi,
min_val=-56 * 1e6 * 2 * np.pi,
max_val=-52 * 1e6 * 2 * np.pi,
unit="Hz 2pi",
),
"delta": Quantity(value=-1, min_val=-5, max_val=3, unit=""),
}
gauss_env_single = Envelope(
name="gauss",
desc="Gaussian comp for single-qubit gates",
params=gauss_params_single,
shape=envelopes["gaussian_nonorm"],
)
carrier_parameters = {
"freq": Quantity(
value=5e9 * 2 * np.pi,
min_val=4.5e9 * 2 * np.pi,
max_val=6e9 * 2 * np.pi,
unit="Hz 2pi",
),
"framechange": Quantity(
value=0.0, min_val=-np.pi, max_val=3 * np.pi, unit="rad"
),
}
carr = Carrier(
name="carrier",
desc="Frequency of the local oscillator",
params=carrier_parameters,
)
rx90p_q1 = Instruction(name="rx90p", t_start=0.0, t_end=t_final, channels=["d1"])
rx90p_q1.add_component(gauss_env_single, "d1")
rx90p_q1.add_component(carr, "d1")
gen.generate_signals(rx90p_q1)
@pytest.mark.unit
def test_signal_generation_from_config() -> None:
"""
Check that signal generation works.
"""
gen.generate_signals(pmap.instructions["rx90p"])
@pytest.mark.integration
def test_parser_integration() -> None:
"""
Check that an Experiment can be initialized.
"""
Exp(pmap=pmap)
@pytest.mark.unit
def test_model_writer() -> None:
model.asdict()
@pytest.mark.unit
def test_generator_writer() -> None:
gen.asdict()
@pytest.mark.unit
def test_pmap_writer() -> None:
pmap.asdict()