This program is a Bell Test, which entangles two qubits so that their measured results are either both 1, or both 0. It uses the IBM Runtime. You will need to first set up your runtime environment with your IBMid. You may also need to change the instance in service.backend().
from qiskit_ibm_runtime import QiskitRuntimeService
from qiskit import QuantumCircuit
from qiskit.quantum_info import SparsePauliOp
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
from qiskit_ibm_runtime import EstimatorV2 as Estimator
from qiskit_ibm_runtime import SamplerV2 as Sampler
service = QiskitRuntimeService()
backend = service.backend("ibm_rensselaer", instance="rpi-rensselaer/general/general")
qc = QuantumCircuit(2)
qc.h(0)
#qc.h(1)
qc.cx(0,1)
qc.measure_all()
pm = generate_preset_pass_manager(backend=backend, optimization_level=1)
isa_circuit = pm.run(qc)
sampler = Sampler(backend)
job = sampler.run([isa_circuit])
print(f"job id: {job.job_id()}")
result = job.result()
print(result)
# Get results from Databin
pub_result = result[0]
counts = pub_result.data.meas.get_counts()
print(f"Counts for the meas output register: {counts}")
# Plot results
from qiskit.visualization import plot_histogram
plot_histogram(counts)
Comments
0 comments
Article is closed for comments.