@@ -179,6 +179,7 @@ def main():
179
179
"--static" , action = "store_true" , help = "compute with " "static mode"
180
180
)
181
181
parser .add_argument ("--pdb" , action = "store_true" , help = "debug with pdb" )
182
+ parser .add_argument ("--qiskit-simulation" , action = "store_true" , help = "run on a real quantum computer" )
182
183
parser .add_argument (
183
184
"--wires-per-block" , type = int , default = 2 , help = "wires per block int static mode"
184
185
)
@@ -243,38 +244,39 @@ def main():
243
244
# test
244
245
valid_test (dataflow , "test" , model , device , qiskit = False )
245
246
246
- # run on Qiskit simulator and real Quantum Computers
247
- try :
248
- from qiskit import IBMQ
249
- from torchquantum .plugin import QiskitProcessor
250
-
251
- # firstly perform simulate
252
- print (f"\n Test with Qiskit Simulator" )
253
- processor_simulation = QiskitProcessor (use_real_qc = False )
254
- model .set_qiskit_processor (processor_simulation )
255
- valid_test (dataflow , "test" , model , device , qiskit = True )
256
-
257
- # then try to run on REAL QC
258
- backend_name = "ibmq_lima"
259
- print (f"\n Test on Real Quantum Computer { backend_name } " )
260
- # Please specify your own hub group and project if you have the
261
- # IBMQ premium plan to access more machines.
262
- processor_real_qc = QiskitProcessor (
263
- use_real_qc = True ,
264
- backend_name = backend_name ,
265
- hub = "ibm-q" ,
266
- group = "open" ,
267
- project = "main" ,
268
- )
269
- model .set_qiskit_processor (processor_real_qc )
270
- valid_test (dataflow , "test" , model , device , qiskit = True )
271
- except ImportError :
272
- print (
273
- "Please install qiskit, create an IBM Q Experience Account and "
274
- "save the account token according to the instruction at "
275
- "'https://github.com/Qiskit/qiskit-ibmq-provider', "
276
- "then try again."
277
- )
247
+ if args .qiskit_simulation :
248
+ # run on Qiskit simulator and real Quantum Computers
249
+ try :
250
+ from qiskit import IBMQ
251
+ from torchquantum .plugin import QiskitProcessor
252
+
253
+ # firstly perform simulate
254
+ print (f"\n Test with Qiskit Simulator" )
255
+ processor_simulation = QiskitProcessor (use_real_qc = False )
256
+ model .set_qiskit_processor (processor_simulation )
257
+ valid_test (dataflow , "test" , model , device , qiskit = True )
258
+
259
+ # then try to run on REAL QC
260
+ backend_name = "ibmq_lima"
261
+ print (f"\n Test on Real Quantum Computer { backend_name } " )
262
+ # Please specify your own hub group and project if you have the
263
+ # IBMQ premium plan to access more machines.
264
+ processor_real_qc = QiskitProcessor (
265
+ use_real_qc = True ,
266
+ backend_name = backend_name ,
267
+ hub = "ibm-q" ,
268
+ group = "open" ,
269
+ project = "main" ,
270
+ )
271
+ model .set_qiskit_processor (processor_real_qc )
272
+ valid_test (dataflow , "test" , model , device , qiskit = True )
273
+ except ImportError :
274
+ print (
275
+ "Please install qiskit, create an IBM Q Experience Account and "
276
+ "save the account token according to the instruction at "
277
+ "'https://github.com/Qiskit/qiskit-ibmq-provider', "
278
+ "then try again."
279
+ )
278
280
279
281
280
282
if __name__ == "__main__" :
0 commit comments