Пример #1
0
 def test_api_run_experiment(self):
     '''
     Check run an experiment by user authenticated
     '''
     api = IBMQuantumExperience(API_TOKEN)
     device = 'simulator'
     shots = 1
     experiment = api.run_experiment(qasm, device, shots)
     self.assertIsNotNone(experiment['status'])
Пример #2
0
 def test_api_run_experiment_fail_device(self):
     '''
     Check run an experiment by user authenticated is not run because the
     device does not exist
     '''
     api = IBMQuantumExperience(API_TOKEN)
     device = '5qreal'
     shots = 1
     experiment = api.run_experiment(qasm, device, shots)
     self.assertIsNotNone(experiment['error'])
Пример #3
0
 def test_api_run_experiment_with_seed(self):
     '''
     Check run an experiment with seed by user authenticated
     '''
     api = IBMQuantumExperience(API_TOKEN)
     device = 'simulator'
     shots = 1
     seed = 815
     experiment = api.run_experiment(qasm, device, shots, seed=seed)
     self.assertEqual(int(experiment['result']['extraInfo']['seed']), seed)
Пример #4
0
 def test_api_run_experiment(self):
     '''
     Check run an experiment by user authenticated
     '''
     api = IBMQuantumExperience(API_TOKEN)
     backend = api.available_backend_simulators()[0]['name']
     shots = 1
     experiment = api.run_experiment(self.qasm, backend, shots)
     check_status = None
     if 'status' in experiment:
         check_status = experiment['status']
     self.assertIsNotNone(check_status)
Пример #5
0
 def test_api_run_experiment_with_seed(self):
     '''
     Check run an experiment with seed by user authenticated
     '''
     api = IBMQuantumExperience(API_TOKEN)
     backend = api.available_backend_simulators()[0]['name']
     shots = 1
     seed = 815
     experiment = api.run_experiment(self.qasm, backend, shots, seed=seed)
     check_seed = -1
     if ('result' in experiment) and \
        ('extraInfo' in experiment['result']) and \
        ('seed' in experiment['result']['extraInfo']):
         check_seed = int(experiment['result']['extraInfo']['seed'])
     self.assertEqual(check_seed, seed)
Пример #6
0
sys.path.append('IBMQuantumExperience')
sys.path.append('../IBMQuantumExperience')
# pylint: disable=C0413
try:
    if sys.version_info.major > 2:  # Python 3
        from IBMQuantumExperience.IBMQuantumExperience import IBMQuantumExperience  # noqa
    else:  # Python 2
        from IBMQuantumExperience import IBMQuantumExperience  # noqa
    from IBMQuantumExperience.IBMQuantumExperience import ApiError
    from IBMQuantumExperience.IBMQuantumExperience import BadBackendError  # noq
except:
    sys.stderr.write(
        "IBMQuantumExperience library not installed. Use : pip install IBMQuantumExperience"
    )
    sys.exit(0)

api = IBMQuantumExperience(sys.argv[1])
# my_credits = api.get_my_credits()
# print "Credits: ", ast.literal_eval(json.dumps(my_credits))
# print "Backend: ",api.available_backend_simulators()[0]['name']

# qasm = 'OPENQASM 2.0;\n\ninclude "qelib1.inc";\nqreg q[5];\ncreg c[5];\nh q[0];\ncx q[0],q[2];\nmeasure q[0] -> c[0];\nmeasure q[2] -> c[1];\n'
# qasm = 'OPENQASM 2.0;\ninclude "qelib1.inc";\nqreg q[5];\ncreg c[5];\nh q[0];\nx q[1];\ncx q[0],q[1];\nmeasure q[0] -> c[0];\nmeasure q[1] -> c[1];'
# print "qasm: ",qasm

backend = api.available_backend_simulators()[0]['name']
shots = sys.argv[2]
experiment = api.run_experiment(qasm, backend, shots)
print ast.literal_eval(json.dumps(experiment))