Skip to content

Commit

Permalink
Merge pull request #610 from qiboteam/rbunrolling
Browse files Browse the repository at this point in the history
Sequence unrolling in standard RB
  • Loading branch information
andrea-pasquale authored Feb 2, 2024
2 parents 687a796 + f42a9f6 commit 2f7d459
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pandas as pd
import plotly.graph_objects as go
import qibo
from qibo.backends import GlobalBackend
from qibolab.platform import Platform
from qibolab.qubits import QubitId

Expand Down Expand Up @@ -50,6 +51,9 @@ class StandardRBParameters(Parameters):
"""Number of bootstrap iterations for the fit uncertainties and error bars.
If ``0``, gets the fit uncertainties from the fitting function and the error bars
from the distribution of the measurements. Defaults to ``100``."""
unrolling: bool = False
"""If ``True`` it uses sequence unrolling to deploy multiple circuits in a single instrument call.
Defaults to ``False``."""
seed: Optional[int] = None
"""A fixed seed to initialize ``np.random.Generator``. If ``None``, uses a random seed.
Defaults is ``None``."""
Expand Down Expand Up @@ -211,21 +215,38 @@ def _acquisition(
noise_model = getattr(noisemodels, params.noise_model)(params.noise_params)
params.noise_params = noise_model.params

# Grab activated qibo backend
backend = GlobalBackend()

# 1. Set up the scan (here an iterator of circuits of random clifford gates with an inverse).
nqubits = platform.nqubits if platform else max(qubits) + 1
scan = setup_scan(params, qubits, nqubits)

# 2. Execute the scan.
data_list = []
# Iterate through the scan and execute each circuit.
# Iterate through the scan and create circuits
circuits = []
depths = []
for circuit in scan:
# The inverse and measurement gate don't count for the depth.
depth = (circuit.depth - 2) if circuit.depth > 1 else 0
depths.append((circuit.depth - 2) if circuit.depth > 1 else 0)
if noise_model is not None:
circuit = noise_model.apply(circuit)
samples = circuit.execute(nshots=params.nshots).samples()
# Every executed circuit gets a row where the data is stored.
data_list.append({"depth": depth, "samples": samples})
circuits.append(circuit)

# Execute the circuits
if params.unrolling:
results = backend.execute_circuits(circuits, nshots=params.nshots)
else:
results = [
backend.execute_circuit(circuit, nshots=params.nshots)
for circuit in circuits
]

# Every executed circuit gets a row where the data is stored.
data_list = [
{"depth": depth, "samples": result.samples()}
for depth, result in zip(depths, results)
]

# Build the data object which will be returned and later saved.
data = pd.DataFrame(data_list)

Expand Down
14 changes: 14 additions & 0 deletions tests/runcards/protocols.yml
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,20 @@ actions:
uncertainties: None
n_bootstrap: 0

- id: standard rb unrolling
priority: 0
operation: standard_rb
parameters:
depths:
start: 1
stop: 10
step: 2
niter: 2
nshots: 50
unrolling: True
uncertainties: None
n_bootstrap: 0

- id: standard rb bootstrap
priority: 0
operation: standard_rb
Expand Down

0 comments on commit 2f7d459

Please sign in to comment.