QuantumCircuit addons¶
import numpy as np
from qiskit import QuantumCircuit
import kaleidoscope.qiskit
from kaleidoscope import probability_distribution
from kaleidoscope.qiskit.services import Simulators
Adding a target backend to a circuit¶
sim = Simulators.aer_lima_simulator
qc = QuantumCircuit(5, 5) >> sim
print(qc.target_backend)
aer_lima_simulator
Transpiling for assigned target backend¶
qc = QuantumCircuit(5, 5) >> sim
qc.h(0)
qc.cx(0, range(1,5))
qc.measure(range(5), range(5))
new_qc = qc.transpile()
new_qc.draw('mpl')
Transpiling for different backend¶
new_sim = Simulators.aer_belem_simulator
new_qc = qc.transpile(backend=new_sim)
print(new_qc.target_backend)
new_qc.draw('mpl')
aer_belem_simulator
Sampling from a target backend¶
counts = new_qc.sample(shots=2048).result_when_done()
probability_distribution(counts)
Getting a statevector¶
qc = QuantumCircuit(3, 3)
qc.h(0)
qc.cx(0, range(1,3))
qc.measure(range(3), range(3))
qc.statevector()
Statevector([0.70710678+0.j, 0. +0.j, 0. +0.j,
0. +0.j, 0. +0.j, 0. +0.j,
0. +0.j, 0.70710678+0.j],
dims=(2, 2, 2))
Getting a unitary¶
qc = QuantumCircuit(3, 3)
qc.h(0)
qc.cx(0, range(1,3))
qc.measure(range(3), range(3))
qc.unitary()
Operator([[ 0.70710678+0.j, 0.70710678+0.j, 0. +0.j,
0. +0.j, 0. +0.j, 0. +0.j,
0. +0.j, 0. +0.j],
[ 0. +0.j, 0. +0.j, 0. +0.j,
0. +0.j, 0. +0.j, 0. +0.j,
0.70710678+0.j, -0.70710678+0.j],
[ 0. +0.j, 0. +0.j, 0.70710678+0.j,
0.70710678+0.j, 0. +0.j, 0. +0.j,
0. +0.j, 0. +0.j],
[ 0. +0.j, 0. +0.j, 0. +0.j,
0. +0.j, 0.70710678+0.j, -0.70710678+0.j,
0. +0.j, 0. +0.j],
[ 0. +0.j, 0. +0.j, 0. +0.j,
0. +0.j, 0.70710678+0.j, 0.70710678+0.j,
0. +0.j, 0. +0.j],
[ 0. +0.j, 0. +0.j, 0.70710678+0.j,
-0.70710678+0.j, 0. +0.j, 0. +0.j,
0. +0.j, 0. +0.j],
[ 0. +0.j, 0. +0.j, 0. +0.j,
0. +0.j, 0. +0.j, 0. +0.j,
0.70710678+0.j, 0.70710678+0.j],
[ 0.70710678+0.j, -0.70710678+0.j, 0. +0.j,
0. +0.j, 0. +0.j, 0. +0.j,
0. +0.j, 0. +0.j]],
input_dims=(2, 2, 2), output_dims=(2, 2, 2))