@@ -36,18 +36,19 @@ def text(self):
36
36
return self .json
37
37
38
38
39
- def _make_sampler () -> cirq_pasqal .PasqalSampler :
39
+ def _make_sampler (device ) -> cirq_pasqal .PasqalSampler :
40
40
41
- sampler = cirq_pasqal .PasqalSampler (remote_host = 'http://00.00.00/' , access_token = 'N/A' )
41
+ sampler = cirq_pasqal .PasqalSampler (
42
+ remote_host = 'http://00.00.00/' , access_token = 'N/A' , device = device
43
+ )
42
44
return sampler
43
45
44
46
45
47
def test_pasqal_circuit_init ():
46
48
qs = cirq .NamedQubit .range (3 , prefix = 'q' )
47
49
ex_circuit = cirq .Circuit ()
48
50
ex_circuit .append ([[cirq .CZ (qs [i ], qs [i + 1 ]), cirq .X (qs [i + 1 ])] for i in range (len (qs ) - 1 )])
49
- device = cirq_pasqal .PasqalDevice (qubits = qs )
50
- test_circuit = cirq .Circuit (device = device )
51
+ test_circuit = cirq .Circuit ()
51
52
test_circuit .append (
52
53
[[cirq .CZ (qs [i ], qs [i + 1 ]), cirq .X (qs [i + 1 ])] for i in range (len (qs ) - 1 )]
53
54
)
@@ -74,22 +75,22 @@ def test_run_sweep(mock_post, mock_get):
74
75
binary = bin (num )[2 :].zfill (9 )
75
76
76
77
device = cirq_pasqal .PasqalVirtualDevice (control_radius = 1 , qubits = qs )
77
- ex_circuit = cirq .Circuit (device = device )
78
+ ex_circuit = cirq .Circuit ()
78
79
79
80
for i , b in enumerate (binary [:- 1 ]):
80
81
if b == '1' :
81
82
ex_circuit .append (cirq .X (qs [- i - 1 ]), strategy = cirq .InsertStrategy .NEW )
82
83
83
84
ex_circuit_odd = copy .deepcopy (ex_circuit )
84
- ex_circuit_odd .append (cirq .X (qs [0 ]))
85
- ex_circuit_odd .append (cirq .measure (* qs ))
85
+ ex_circuit_odd .append (cirq .X (qs [0 ]), strategy = cirq . InsertStrategy . NEW )
86
+ ex_circuit_odd .append (cirq .measure (* qs ), strategy = cirq . InsertStrategy . NEW )
86
87
87
88
xpow = cirq .XPowGate (exponent = par )
88
- ex_circuit .append ([xpow (qs [0 ])])
89
- ex_circuit .append (cirq .measure (* qs ))
89
+ ex_circuit .append ([xpow (qs [0 ])], strategy = cirq . InsertStrategy . NEW )
90
+ ex_circuit .append (cirq .measure (* qs ), strategy = cirq . InsertStrategy . NEW )
90
91
91
92
mock_get .return_value = MockGet (cirq .to_json (ex_circuit_odd ))
92
- sampler = _make_sampler ()
93
+ sampler = _make_sampler (device )
93
94
94
95
with pytest .raises (ValueError , match = "Non-empty moment after measurement" ):
95
96
wrong_circuit = copy .deepcopy (ex_circuit )
@@ -102,3 +103,42 @@ def test_run_sweep(mock_post, mock_get):
102
103
assert cirq .read_json (json_text = submitted_json ) == ex_circuit_odd
103
104
assert mock_post .call_count == 2
104
105
assert data [1 ] == ex_circuit_odd
106
+
107
+
108
+ @patch ('cirq_pasqal.pasqal_sampler.requests.get' )
109
+ @patch ('cirq_pasqal.pasqal_sampler.requests.post' )
110
+ def test_run_sweep_device_deprecated (mock_post , mock_get ):
111
+ """Test running a sweep.
112
+
113
+ Encodes a random binary number in the qubits, sweeps between odd and even
114
+ without noise and checks if the results match.
115
+ """
116
+
117
+ qs = [cirq_pasqal .ThreeDQubit (i , j , 0 ) for i in range (3 ) for j in range (3 )]
118
+
119
+ par = sympy .Symbol ('par' )
120
+ sweep = cirq .Linspace (key = 'par' , start = 0.0 , stop = 1.0 , length = 2 )
121
+
122
+ num = np .random .randint (0 , 2 ** 9 )
123
+ binary = bin (num )[2 :].zfill (9 )
124
+
125
+ device = cirq_pasqal .PasqalVirtualDevice (control_radius = 1 , qubits = qs )
126
+ ex_circuit = cirq .Circuit ()
127
+
128
+ for i , b in enumerate (binary [:- 1 ]):
129
+ if b == '1' :
130
+ ex_circuit .append (cirq .X (qs [- i - 1 ]), strategy = cirq .InsertStrategy .NEW )
131
+
132
+ ex_circuit_odd = copy .deepcopy (ex_circuit )
133
+ ex_circuit_odd .append (cirq .X (qs [0 ]), strategy = cirq .InsertStrategy .NEW )
134
+ ex_circuit_odd .append (cirq .measure (* qs ), strategy = cirq .InsertStrategy .NEW )
135
+
136
+ xpow = cirq .XPowGate (exponent = par )
137
+ ex_circuit .append ([xpow (qs [0 ])], strategy = cirq .InsertStrategy .NEW )
138
+ ex_circuit .append (cirq .measure (* qs ), strategy = cirq .InsertStrategy .NEW )
139
+
140
+ mock_get .return_value = MockGet (cirq .to_json (ex_circuit_odd ))
141
+ sampler = _make_sampler (device )
142
+ ex_circuit ._device = device
143
+ with cirq .testing .assert_deprecated ('The program.device component' , deadline = 'v0.15' ):
144
+ _ = sampler .run_sweep (program = ex_circuit , params = sweep , repetitions = 1 )
0 commit comments