23
23
from pytket import Circuit
24
24
from pytket .extensions .qiskit import AerBackend # type: ignore
25
25
from pytket .extensions .quantinuum import QuantinuumBackend , QuantinuumAPIOffline
26
- from qermit .frame_randomisation .h_series_randomisation import gen_randomised_circuit
26
+ from qermit .frame_randomisation .h_series_randomisation import gen_h_series_randomised_circuit , get_wfh
27
+
27
28
from pytket .unit_id import BitRegister
28
29
from collections import Counter
29
30
30
31
31
32
def test_h_series_randomisation ():
33
+ # These tests check that the ideal behaviour of the circuits
34
+ # is not altered by adding randomisation.
32
35
33
36
api_offline = QuantinuumAPIOffline ()
34
37
backend = QuantinuumBackend (
35
38
device_name = "H1-1LE" ,
36
39
api_handler = api_offline ,
37
40
)
41
+ wasm_file_handler = get_wfh ()
38
42
43
+ # Small circuit with just one ZZMax.
44
+ # The ideal output is 00.
39
45
circuit = Circuit (3 )
40
46
meas_reg = BitRegister (name = 'measure' , size = 2 )
41
47
circuit .add_c_register (meas_reg )
@@ -50,19 +56,100 @@ def test_h_series_randomisation():
50
56
bit = meas_reg [1 ]
51
57
)
52
58
53
- randomised_circuit , wfh = gen_randomised_circuit (circuit )
54
-
59
+ randomised_circuit = gen_h_series_randomised_circuit (circuit )
55
60
compiled_circuit = backend .get_compiled_circuit (randomised_circuit , optimisation_level = 0 )
56
61
57
62
n_shots = 100
58
63
result = backend .run_circuit (
59
64
compiled_circuit ,
60
65
n_shots = n_shots ,
61
- wasm_file_handler = wfh ,
66
+ wasm_file_handler = wasm_file_handler ,
62
67
no_opt = True
63
68
)
64
69
assert result .get_counts (cbits = meas_reg ) == Counter ({(0 ,0 ,): n_shots })
65
70
71
+ # To consecutive ZZMax gates.
72
+ # Has the effect of acting Z_0 Z_1.
73
+ # Checked by applying hadamard rotations.
74
+ # I deal outcome in rotate basis is 11.
75
+ circuit = Circuit (3 )
76
+ meas_reg = BitRegister (name = 'measure' , size = 2 )
77
+ circuit .add_c_register (meas_reg )
78
+
79
+ circuit .H (0 )
80
+ circuit .H (1 )
81
+
82
+ circuit .ZZMax (0 ,1 )
83
+ circuit .ZZMax (0 ,1 )
84
+
85
+ circuit .H (0 )
86
+ circuit .H (1 )
87
+
88
+ circuit .Measure (
89
+ qubit = circuit .qubits [0 ],
90
+ bit = meas_reg [0 ]
91
+ )
92
+ circuit .Measure (
93
+ qubit = circuit .qubits [1 ],
94
+ bit = meas_reg [1 ]
95
+ )
96
+
97
+ randomised_circuit = gen_h_series_randomised_circuit (circuit )
98
+ compiled_circuit = backend .get_compiled_circuit (randomised_circuit , optimisation_level = 0 )
99
+
100
+ n_shots = 100
101
+ result = backend .run_circuit (
102
+ compiled_circuit ,
103
+ n_shots = n_shots ,
104
+ wasm_file_handler = wasm_file_handler ,
105
+ no_opt = True
106
+ )
107
+ assert result .get_counts (cbits = meas_reg ) == Counter ({(1 ,1 ,): n_shots })
108
+
109
+ # Slightly larger circuit.
110
+ # Ideal outcome in rotated basis is 101.
111
+ circuit = Circuit (3 )
112
+ meas_reg = BitRegister (name = 'measure' , size = 3 )
113
+ circuit .add_c_register (meas_reg )
114
+
115
+ circuit .H (0 )
116
+ circuit .H (1 )
117
+ circuit .H (2 )
118
+
119
+ circuit .ZZMax (0 ,1 )
120
+ circuit .ZZMax (1 ,2 )
121
+ circuit .ZZMax (0 ,1 )
122
+ circuit .ZZMax (1 ,2 )
123
+
124
+ circuit .H (0 )
125
+ circuit .H (1 )
126
+ circuit .H (2 )
127
+
128
+ circuit .Measure (
129
+ qubit = circuit .qubits [0 ],
130
+ bit = meas_reg [0 ]
131
+ )
132
+ circuit .Measure (
133
+ qubit = circuit .qubits [1 ],
134
+ bit = meas_reg [1 ]
135
+ )
136
+ circuit .Measure (
137
+ qubit = circuit .qubits [2 ],
138
+ bit = meas_reg [2 ]
139
+ )
140
+
141
+ randomised_circuit = gen_h_series_randomised_circuit (circuit )
142
+ compiled_circuit = backend .get_compiled_circuit (randomised_circuit , optimisation_level = 0 )
143
+
144
+ n_shots = 100
145
+ result = backend .run_circuit (
146
+ compiled_circuit ,
147
+ n_shots = n_shots ,
148
+ wasm_file_handler = wasm_file_handler ,
149
+ no_opt = True
150
+ )
151
+ assert result .get_counts (cbits = meas_reg ) == Counter ({(1 ,0 ,1 ,): n_shots })
152
+
66
153
def test_frame_randomisation_circuits_task_gen ():
67
154
c = Circuit (2 ).CX (0 , 1 ).Rx (0.289 , 1 ).CX (0 , 1 ).measure_all ()
68
155
ufr_task = frame_randomisation_circuits_task_gen (
0 commit comments