11
11
from qiskit_ibm_runtime .program import UserMessenger
12
12
from scipy .optimize import dual_annealing
13
13
import statistics
14
+ from qiskit .compiler import transpile
15
+ from qiskit .quantum_info import SparsePauliOp
16
+ from qiskit_ibm_runtime import Estimator , QiskitRuntimeService , Session
14
17
15
18
@ct .electron
16
19
def fetch_data (id ):
@@ -31,13 +34,28 @@ def fetch_data(id):
31
34
return scores
32
35
33
36
@ct .electron
34
- def predict_trouble (example , parameters = [0.8683269 , 0.39393166 , 0.47681407 , 0.30033276 , 0.97830805 , 0.52097628 , 0.99194506 , 0.92128744 , 0.57695905 , 0.36047569 ,0.83097868 , 0.47035325 ]):
37
+ @ct .lattice
38
+ def predict_trouble (token , example , parameters = [0.8683269 , 0.39393166 , 0.47681407 , 0.30033276 , 0.97830805 , 0.52097628 , 0.99194506 , 0.92128744 , 0.57695905 , 0.36047569 ,0.83097868 , 0.47035325 ]):
35
39
qc = QuantumCircuit (3 )
36
40
embed_example (qc , example )
37
41
apply_parameters (qc , parameters )
42
+ evaluate_circuit (qc , token )
38
43
result = run_circuit (qc , Aer .get_backend ("aer_simulator" ))
39
44
return make_prediction (result )
40
45
46
+ @ct .electron (deps_pip = ct .DepsPip (["qiskit==0.40.0" ]))
47
+ def evaluate_circuit (qc , token : str ):
48
+ QiskitRuntimeService .save_account (channel = "ibm_quantum" ,
49
+ token = token ,
50
+ instance = "ibm-q-community/mit-hackathon/main" ,
51
+ overwrite = True )
52
+
53
+ with Session (service = QiskitRuntimeService (), backend = "ibm_nairobi" ):
54
+ estimator = Estimator ()
55
+ return estimator .run (circuits = qc ,
56
+ observables = [SparsePauliOp ("IZ" )],
57
+ shots = 500 ).result ()
58
+
41
59
42
60
def embed_example (circuit , example ):
43
61
circuit .rx (np .pi * example [0 ], 0 )
0 commit comments