-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathui_test.py
126 lines (116 loc) · 3.52 KB
/
ui_test.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
# Copyright 2024 Google LLC
#
# 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
#
# https://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.
import pytest
from dash.exceptions import PreventUpdate
from qualtran.surface_code import ui
@pytest.mark.parametrize('estimation_model', ui._SUPPORTED_ESTIMATION_MODELS)
def test_ensure_support_for_all_supported_models(estimation_model: str):
# Make sure the update runs without failure for all supported models.
_ = ui.update(
physical_error_rate=1e-4,
error_budget=1e-3,
estimation_model=estimation_model,
algorithm_data=(10**11,) * 6,
qec_name='GidneyFowler',
magic_name='FifteenToOne733',
magic_count=1,
rotaion_model_name='BeverlandEtAlRotationCost',
)
@pytest.mark.parametrize(
'estimation_model,desired',
[
(
ui._GIDNEY_FOWLER_MODEL,
(
{'display': 'none'},
['Total Number of Toffoli gates'],
'9e+11',
{'display': 'none'},
1,
{'display': 'block'},
'2914.93 days',
),
),
(
ui._BEVERLAND_MODEL,
(
{'display': 'block'},
['Total Number of T gates'],
'3.6e+12',
{'display': 'block'},
18,
{'display': 'none'},
'',
),
),
],
)
def test_update(estimation_model: str, desired):
(
_,
display_runtime,
_,
magic_name,
magic_count,
display_factory_count,
factory_count,
display_duration,
duration,
) = ui.update(
physical_error_rate=1e-4,
error_budget=1e-3,
estimation_model=estimation_model,
algorithm_data=(10**11,) * 6,
qec_name='GidneyFowler',
magic_name='FifteenToOne733',
magic_count=1,
rotaion_model_name='BeverlandEtAlRotationCost',
)
assert (
display_runtime,
magic_name,
magic_count,
display_factory_count,
factory_count,
display_duration,
duration,
) == desired
def test_update_bad_input():
with pytest.raises(PreventUpdate):
_ = ui.update(
physical_error_rate=None,
error_budget=1e-3,
estimation_model=ui._SUPPORTED_ESTIMATION_MODELS[0],
algorithm_data=(10**11,) * 6,
qec_name='GidneyFowler',
magic_name='FifteenToOne733',
magic_count=1,
rotaion_model_name='BeverlandEtAlRotationCost',
)
@pytest.mark.parametrize(
['duration', 'desired'],
[
(25000, ("ms", 25)),
(9, ("us", 9)),
(1009, ("ms", 1)),
(7001009, ("s", 7)),
(300700190, ("min", 5)),
(24300700100, ("hours", 7)),
(7443007001009, ("days", 86)),
],
)
def test_formatting(duration: int, desired: str):
unit, (final_duration,) = ui.format_duration([duration])
assert unit == desired[0]
assert round(final_duration) == desired[1]