-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimpleBell.py
24 lines (21 loc) · 1.1 KB
/
SimpleBell.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from qiskit import QuantumCircuit
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
from qiskit_ibm_runtime import QiskitRuntimeService, SamplerV2 as Sampler
#QiskitRuntimeService.save_account(channel="ibm_quantum", token="ce86c729e968c408536dbcbc12a10c6c653fc08436381379d6b03b3ba99cead56b4c1b8a5716f104d2975c2412b7270024ba85f29634bdfafe3c2bf2688040fa")
service = QiskitRuntimeService()
# 1. A quantum circuit for preparing the quantum state (|00> + |11>)/rt{2}
bell = QuantumCircuit(2)
bell.h(0)
bell.cx(0, 1)
bell.measure_all()
# 2: Optimize problem for quantum execution.
backend = service.least_busy(operational=True, simulator=False)
pm = generate_preset_pass_manager(backend=backend, optimization_level=1)
isa_circuit = pm.run(bell)
# 3. Execute using the Sampler primitive
sampler = Sampler(mode=backend)
sampler.options.default_shots = 1024 # Options can be set using auto-complete.
job = sampler.run([isa_circuit])
print(f"Job ID is {job.job_id()}")
pub_result = job.result()[0]
print(f"Counts for the meas output register: {pub_result.data.meas.get_counts()}")