@@ -51,8 +51,9 @@ def test_schedule_circuit_when_backend_tells_dt(self):
51
51
backend = GenericBackendV2 (2 , seed = 42 )
52
52
53
53
sc = transpile (qc , backend , scheduling_method = "alap" , layout_method = "trivial" )
54
- self .assertEqual (sc .duration , 451095 )
55
- self .assertEqual (sc .unit , "dt" )
54
+ with self .assertRaises (DeprecationWarning ):
55
+ self .assertEqual (sc .duration , 451095 )
56
+ self .assertEqual (sc .unit , "dt" )
56
57
self .assertEqual (sc .data [0 ].operation .name , "delay" )
57
58
self .assertEqual (sc .data [0 ].operation .duration , 450900 )
58
59
self .assertEqual (sc .data [0 ].operation .unit , "dt" )
@@ -77,8 +78,9 @@ def test_schedule_circuit_when_transpile_option_tells_dt(self):
77
78
seed_transpiler = 20 ,
78
79
)
79
80
target_durations = self .backend_with_dt .target .durations ()
80
- self .assertAlmostEqual (sc .duration , (450450 + target_durations .get ("sx" , 0 )))
81
- self .assertEqual (sc .unit , "dt" )
81
+ with self .assertRaises (DeprecationWarning ):
82
+ self .assertAlmostEqual (sc .duration , (450450 + target_durations .get ("sx" , 0 )))
83
+ self .assertEqual (sc .unit , "dt" )
82
84
self .assertEqual (sc .data [0 ].operation .name , "delay" )
83
85
self .assertEqual (sc .data [0 ].operation .duration , 450450 )
84
86
self .assertEqual (sc .data [0 ].operation .unit , "dt" )
@@ -101,8 +103,10 @@ def test_schedule_circuit_in_sec_when_no_one_tells_dt(self):
101
103
qc , self .backend_without_dt , scheduling_method = "alap" , layout_method = "trivial"
102
104
)
103
105
target_durations = self .backend_with_dt .target .durations ()
104
- self .assertAlmostEqual (sc .duration , (450450 + target_durations .get ("sx" , 0 )) * self .dt )
105
- self .assertEqual (sc .unit , "s" )
106
+
107
+ with self .assertRaises (DeprecationWarning ):
108
+ self .assertAlmostEqual (sc .duration , (450450 + target_durations .get ("sx" , 0 )) * self .dt )
109
+ self .assertEqual (sc .unit , "s" )
106
110
self .assertEqual (sc .data [0 ].operation .name , "delay" )
107
111
self .assertAlmostEqual (sc .data [0 ].operation .duration , 1.0e-4 + 1.0e-7 )
108
112
self .assertEqual (sc .data [0 ].operation .unit , "s" )
@@ -125,7 +129,8 @@ def test_transpile_single_delay_circuit(self):
125
129
qc = QuantumCircuit (1 )
126
130
qc .delay (1234 , 0 )
127
131
sc = transpile (qc , backend = self .backend_with_dt , scheduling_method = "alap" )
128
- self .assertEqual (sc .duration , 1234 )
132
+ with self .assertRaises (DeprecationWarning ):
133
+ self .assertEqual (sc .duration , 1234 )
129
134
self .assertEqual (sc .data [0 ].operation .name , "delay" )
130
135
self .assertEqual (sc .data [0 ].operation .duration , 1234 )
131
136
self .assertEqual (sc .data [0 ].operation .unit , "dt" )
@@ -141,7 +146,8 @@ def test_transpile_t1_circuit(self):
141
146
expected_scheduled = (
142
147
target_durations .get ("x" , 1 ) + 4500 + target_durations .get ("measure" , 1 )
143
148
)
144
- self .assertEqual (scheduled .duration , expected_scheduled )
149
+ with self .assertRaises (DeprecationWarning ):
150
+ self .assertEqual (scheduled .duration , expected_scheduled )
145
151
146
152
def test_transpile_delay_circuit_with_backend (self ):
147
153
qc = QuantumCircuit (2 )
@@ -152,7 +158,8 @@ def test_transpile_delay_circuit_with_backend(self):
152
158
qc , backend = self .backend_with_dt , scheduling_method = "alap" , layout_method = "trivial"
153
159
)
154
160
target_durations = self .backend_with_dt .target .durations ()
155
- self .assertEqual (scheduled .duration , target_durations .get ("cx" , (0 , 1 )) + 450 )
161
+ with self .assertRaises (DeprecationWarning ):
162
+ self .assertEqual (scheduled .duration , target_durations .get ("cx" , (0 , 1 )) + 450 )
156
163
157
164
def test_transpile_circuit_with_custom_instruction (self ):
158
165
"""See: https://github.com/Qiskit/qiskit-terra/issues/5154"""
@@ -184,13 +191,15 @@ def test_transpile_circuit_with_custom_instruction(self):
184
191
target = target ,
185
192
dt = 1e-2 ,
186
193
)
187
- self .assertEqual (scheduled .duration , 1500 )
194
+ with self .assertRaises (DeprecationWarning ):
195
+ self .assertEqual (scheduled .duration , 1500 )
188
196
189
197
def test_transpile_delay_circuit_with_dt_but_without_scheduling_method (self ):
190
198
qc = QuantumCircuit (1 )
191
199
qc .delay (100 , 0 , unit = "ns" )
192
200
transpiled = transpile (qc , backend = self .backend_with_dt )
193
- self .assertEqual (transpiled .duration , None ) # not scheduled
201
+ with self .assertRaises (DeprecationWarning ):
202
+ self .assertEqual (transpiled .duration , None ) # not scheduled
194
203
self .assertEqual (transpiled .data [0 ].operation .duration , 450 ) # unit is converted ns -> dt
195
204
196
205
def test_transpile_delay_circuit_without_scheduling_method_or_durs (self ):
@@ -199,7 +208,8 @@ def test_transpile_delay_circuit_without_scheduling_method_or_durs(self):
199
208
qc .delay (500 , 1 )
200
209
qc .cx (0 , 1 )
201
210
not_scheduled = transpile (qc )
202
- self .assertEqual (not_scheduled .duration , None )
211
+ with self .assertRaises (DeprecationWarning ):
212
+ self .assertEqual (not_scheduled .duration , None )
203
213
204
214
def test_raise_error_if_transpile_with_scheduling_method_but_without_durations (self ):
205
215
qc = QuantumCircuit (2 )
@@ -217,7 +227,8 @@ def test_invalidate_schedule_circuit_if_new_instruction_is_appended(self):
217
227
scheduled = transpile (qc , backend = self .backend_with_dt , scheduling_method = "alap" )
218
228
# append a gate to a scheduled circuit
219
229
scheduled .h (0 )
220
- self .assertEqual (scheduled .duration , None )
230
+ with self .assertRaises (DeprecationWarning ):
231
+ self .assertEqual (scheduled .duration , None )
221
232
222
233
def test_unit_seconds_when_using_backend_durations (self ):
223
234
qc = QuantumCircuit (2 )
@@ -229,7 +240,8 @@ def test_unit_seconds_when_using_backend_durations(self):
229
240
qc , backend = self .backend_with_dt , scheduling_method = "alap" , layout_method = "trivial"
230
241
)
231
242
target_durations = self .backend_with_dt .target .durations ()
232
- self .assertEqual (scheduled .duration , target_durations .get ("cx" , (0 , 1 )) + 500 )
243
+ with self .assertRaises (DeprecationWarning ):
244
+ self .assertEqual (scheduled .duration , target_durations .get ("cx" , (0 , 1 )) + 500 )
233
245
234
246
def test_per_qubit_durations (self ):
235
247
"""Test target with custom instruction_durations"""
@@ -288,29 +300,32 @@ def test_convert_duration_to_dt(self):
288
300
circ .measure_all ()
289
301
290
302
circuit_dt = transpile (circ , backend , scheduling_method = "asap" )
291
- # reference duration and unit in dt
292
- ref_duration = circuit_dt .duration
293
- ref_unit = circuit_dt .unit
294
-
295
- circuit_s = circuit_dt .copy ()
296
- circuit_s .duration *= backend .dt
297
- circuit_s .unit = "s"
298
-
299
- circuit_ms = circuit_s .copy ()
300
- circuit_ms .duration *= 1000
301
- circuit_ms .unit = "ms"
302
-
303
- for circuit in [circuit_dt , circuit_s , circuit_ms ]:
304
- with self .subTest (circuit = circuit ):
305
- converted_circ = convert_durations_to_dt (circuit , dt_in_sec = 2.22e-10 , inplace = False )
306
- self .assertEqual (
307
- converted_circ .duration ,
308
- ref_duration ,
309
- )
310
- self .assertEqual (
311
- converted_circ .unit ,
312
- ref_unit ,
313
- )
303
+ with self .assertRaises (DeprecationWarning ):
304
+ # reference duration and unit in dt
305
+ ref_duration = circuit_dt .duration
306
+ ref_unit = circuit_dt .unit
307
+
308
+ circuit_s = circuit_dt .copy ()
309
+ circuit_s .duration *= backend .dt
310
+ circuit_s .unit = "s"
311
+
312
+ circuit_ms = circuit_s .copy ()
313
+ circuit_ms .duration *= 1000
314
+ circuit_ms .unit = "ms"
315
+
316
+ for circuit in [circuit_dt , circuit_s , circuit_ms ]:
317
+ with self .subTest (circuit = circuit ):
318
+ converted_circ = convert_durations_to_dt (
319
+ circuit , dt_in_sec = 2.22e-10 , inplace = False
320
+ )
321
+ self .assertEqual (
322
+ converted_circ .duration ,
323
+ ref_duration ,
324
+ )
325
+ self .assertEqual (
326
+ converted_circ .unit ,
327
+ ref_unit ,
328
+ )
314
329
315
330
@data ("s" , "dt" , "f" , "p" , "n" , "u" , "µ" , "m" , "k" , "M" , "G" , "T" , "P" )
316
331
def test_estimate_duration (self , unit ):
@@ -475,15 +490,17 @@ def test_change_dt_in_transpile(self):
475
490
backend = GenericBackendV2 (1 , basis_gates = ["x" ], seed = 2 , dt = self .dt ),
476
491
scheduling_method = "asap" ,
477
492
)
478
- org_duration = scheduled .duration
493
+ with self .assertRaises (DeprecationWarning ):
494
+ org_duration = scheduled .duration
479
495
# halve dt in sec = double duration in dt
480
496
scheduled = transpile (
481
497
qc ,
482
498
backend = GenericBackendV2 (1 , basis_gates = ["x" ], seed = 2 , dt = self .dt ),
483
499
scheduling_method = "asap" ,
484
500
dt = self .dt / 2 ,
485
501
)
486
- self .assertEqual (scheduled .duration , org_duration * 2 )
502
+ with self .assertRaises (DeprecationWarning ):
503
+ self .assertEqual (scheduled .duration , org_duration * 2 )
487
504
488
505
@data ("asap" , "alap" )
489
506
def test_duration_on_same_instruction_instance (self , scheduling_method ):
@@ -509,7 +526,8 @@ def test_can_transpile_circuits_after_assigning_parameters(self):
509
526
qc .measure (0 , 0 )
510
527
qc = qc .assign_parameters ({idle_dur : 0.1 })
511
528
circ = transpile (qc , self .backend_with_dt )
512
- self .assertEqual (circ .duration , None ) # not scheduled
529
+ with self .assertRaises (DeprecationWarning ):
530
+ self .assertEqual (circ .duration , None ) # not scheduled
513
531
self .assertEqual (circ .data [1 ].operation .duration , 450 ) # converted in dt
514
532
515
533
def test_can_transpile_circuits_with_assigning_parameters_inbetween (self ):
@@ -531,7 +549,8 @@ def test_can_transpile_circuits_with_unbounded_parameters(self):
531
549
qc .measure (0 , 0 )
532
550
# not assign parameter
533
551
circ = transpile (qc , self .backend_with_dt )
534
- self .assertEqual (circ .duration , None ) # not scheduled
552
+ with self .assertRaises (DeprecationWarning ):
553
+ self .assertEqual (circ .duration , None ) # not scheduled
535
554
self .assertEqual (circ .data [1 ].operation .unit , "dt" ) # converted in dt
536
555
self .assertEqual (
537
556
circ .data [1 ].operation .duration , idle_dur * 1e-6 / self .dt
@@ -546,7 +565,8 @@ def test_can_schedule_circuits_with_bounded_parameters(self, scheduling_method):
546
565
qc .measure (0 , 0 )
547
566
qc = qc .assign_parameters ({idle_dur : 0.1 })
548
567
circ = transpile (qc , self .backend_with_dt , scheduling_method = scheduling_method )
549
- self .assertIsNotNone (circ .duration ) # scheduled
568
+ with self .assertRaises (DeprecationWarning ):
569
+ self .assertIsNotNone (circ .duration ) # scheduled
550
570
551
571
@data ("asap" , "alap" )
552
572
def test_fail_to_schedule_circuits_with_unbounded_parameters (self , scheduling_method ):
0 commit comments