-
-
Save nelimee/143fb4e308517e1434a264a7615e5c03 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import typing as ty | |
from copy import deepcopy | |
from math import pi | |
from time import time as now | |
import numpy.random | |
from qiskit import IBMQ, QuantumCircuit, pulse, schedule, transpile | |
from qiskit.providers.ibmq.ibmqbackend import IBMQBackend | |
from qiskit.pulse import InstructionScheduleMap, Schedule | |
start = now() | |
n = 100 | |
m = 20 | |
# Random circuit generation with only sqrt(X) or sqrt(Y) gates. | |
rng = numpy.random.default_rng() | |
is_sx_all: numpy.ndarray = rng.integers(low=0, high=2, dtype=bool, size=(m, n)) | |
circuits: ty.List[QuantumCircuit] = list() | |
for is_sx_list in is_sx_all: | |
circuit = QuantumCircuit(1, 1) | |
for is_sx in is_sx_list: | |
if is_sx: | |
circuit.sx(0) | |
else: | |
circuit.rz(-pi / 2, 0) | |
circuit.sx(0) | |
circuit.rz(pi / 2, 0) | |
circuits.append(circuit) | |
end_random_circ_gen = now() | |
print(f"Generated random circuits in {(end_random_circ_gen - start)*1000:.0f} ms") | |
# Recovering backend information from the cloud | |
print("Loading IBMQ account...", end=" ") | |
if not IBMQ.active_account(): | |
IBMQ.load_account() | |
provider = IBMQ.get_provider(hub='ibm-q', group='open', project='main') | |
ibmq_bogota = provider.get_backend("ibmq_bogota") | |
num_qubits: int = ibmq_bogota.configuration().num_qubits | |
print("Done!") | |
rng = numpy.random.default_rng() | |
start_pulse = now() | |
# Create a dummy implementation of the sqrt(X) gate | |
for qubit_index in range(num_qubits): | |
with pulse.build(ibmq_bogota) as sx_impl: | |
pulse.play(pulse.library.Waveform(rng.random(160) / 10), pulse.DriveChannel(0)) | |
for circuit in circuits: | |
circuit.add_calibration("sx", [0], sx_impl) | |
end_pulse = now() | |
print(f"Added calibrations to circuits in {(end_pulse - start_pulse)*1000:.0f} ms.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment