Skip to content

Commit

Permalink
Merge pull request #203 from qiboteam/0.2-upgrader-cal
Browse files Browse the repository at this point in the history
Script to generate calibration.json
  • Loading branch information
stavros11 authored Nov 26, 2024
2 parents 5c8003e + 8267759 commit adb77d1
Show file tree
Hide file tree
Showing 3 changed files with 381 additions and 9 deletions.
131 changes: 122 additions & 9 deletions convert.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
"""Converts parameters.json to parameters.json and calibration.json
"""

import argparse
import ast
import json
from dataclasses import dataclass
from pathlib import Path
from typing import Optional

Expand All @@ -9,16 +13,63 @@

NONSERIAL = lambda: None
"""Raise an error if survives in the final object to be serialized."""
QM_TIME_OF_FLIGHT = 224
"""Default time of flight for QM platforms (in 0.1 this was hard-coded in platform.py)."""


def channel_from_pulse(pulse: dict) -> dict:
return {"kind": "iq", "frequency": pulse["frequency"]}


@dataclass
class QmConnection:
instrument: str
port: str
output_mode: str = "triggered"


def qm_configs(conf: dict, instruments: dict, instrument_channels: dict) -> dict:
for channel, conn in instrument_channels.items():
connection = QmConnection(**conn)
settings = instruments.get(connection.instrument, {}).get(connection.port, {})
if channel in conf:
kind = conf[channel]["kind"]
if kind == "acquisition":
conf[channel].update(
{
"kind": "qm-acquisition",
"delay": QM_TIME_OF_FLIGHT,
"gain": settings.get("gain", 0),
}
)
elif kind == "dc":
conf[channel].update(
{
"kind": "opx-output",
"filter": settings.get("filter", {}),
"output_mode": settings.get("output_mode", "direct"),
}
)
else:
raise NotImplementedError
else:
conf[channel] = {
"kind": "octave-oscillator",
"frequency": settings["lo_frequency"],
"power": settings["gain"],
"output_mode": connection.output_mode,
}
return conf


def configs(
instruments: dict, single: dict, couplers: dict, characterization: dict
instruments: dict,
single: dict,
couplers: dict,
characterization: dict,
connections: Optional[dict] = None,
) -> dict:
return (
conf = (
{
f"{k}/bounds": (v["bounds"] | {"kind": "bounds"})
for k, v in instruments.items()
Expand Down Expand Up @@ -54,6 +105,12 @@ def configs(
for id, char in characterization.get("coupler", {}).items()
}
)
if connections is not None:
if connections["kind"] == "qm":
conf = qm_configs(conf, instruments, connections["channels"])
else:
raise NotImplementedError
return conf


def channel(qubit: str, type_: str, gate: Optional[str] = None) -> str:
Expand Down Expand Up @@ -105,7 +162,7 @@ def pulse(o: dict) -> dict:
"duration": o["duration"],
"amplitude": o["amplitude"],
"envelope": envelope(o["shape"]),
"relative_phase": o.get("phase"),
"relative_phase": o.get("phase", 0.0),
}


Expand Down Expand Up @@ -168,36 +225,92 @@ def natives(o: dict) -> dict:
}


def upgrade(o: dict) -> dict:
def upgrade(o: dict, connections: Optional[dict] = None) -> dict:
return {
"settings": o["settings"],
"configs": configs(
o["instruments"],
o["native_gates"]["single_qubit"],
o["native_gates"].get("coupler", {}),
o["characterization"],
connections,
),
"native_gates": natives(o["native_gates"]),
}


def convert(path: Path):
def single_qubits_cal(o: dict) -> dict:
return {
q: {
"resonator": {
"bare_frequency": k["bare_resonator_frequency"],
"dressed_frequency": k["readout_frequency"],
},
"qubit": {
"frequency_01": k["drive_frequency"],
"sweetspot": k["sweetspot"],
},
"readout": {
"fidelity": k["readout_fidelity"],
"ground_state": k["mean_gnd_states"],
"excited_state": k["mean_exc_states"],
},
"t1": [k["T1"], None],
"t2": [k["T2"], None],
"t2_spin_echo": [k["T2_spin_echo"], None],
"rb_fidelity": [k["gate_fidelity"], None],
}
for q, k in o.items()
}


def two_qubits_cal(o: dict) -> dict:
return {
qq: {
"rb_fidelity": [k["gate_fidelity"], None],
"cz_fidelity": [k["cz_fidelity"], None],
}
for qq, k in o.items()
}


def upgrade_cal(o: dict) -> dict:
return {
"single_qubits": single_qubits_cal(o["characterization"]["single_qubit"]),
"two_qubits": two_qubits_cal(o["characterization"]["two_qubit"]),
}


def convert(path: Path, connections_path: Optional[Path] = None):
params = json.loads(path.read_text())
new = upgrade(params)
connections = (
json.loads(connections_path.read_text())
if connections_path is not None
else None
)
new = upgrade(params, connections)
cal = upgrade_cal(params)
path.with_stem(path.stem + "-new").write_text(json.dumps(new, indent=4))
path.with_stem("calibration").write_text(json.dumps(cal, indent=4))


def parse():
parser = argparse.ArgumentParser()
parser.add_argument("path", nargs="*", type=Path)
parser.add_argument("--connections", nargs="*", default=None, type=Path)
return parser.parse_args()


def main():
args = parse()

for p in args.path:
convert(p)
connections = args.connections
if connections is not None:
assert len(args.path) == len(connections)
else:
connections = len(args.path) * [None]

for p, c in zip(args.path, connections):
convert(p, c)


if __name__ == "__main__":
Expand Down
189 changes: 189 additions & 0 deletions qw11q/connections.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
{
"kind": "qm",
"channels": {
"A1A4/drive_lo": {
"instrument": "octave4",
"port": "o2"
},
"A2A3/drive_lo": {
"instrument": "octave4",
"port": "o4"
},
"A5D5/drive_lo": {
"instrument": "octave6",
"port": "o2"
},
"A6D4/drive_lo": {
"instrument": "octave6",
"port": "o4"
},
"B1/drive_lo": {
"instrument": "octave2",
"port": "o2"
},
"B2/drive_lo": {
"instrument": "octave2",
"port": "o4"
},
"B3/drive_lo": {
"instrument": "octave3",
"port": "o1"
},
"B4/drive_lo": {
"instrument": "octave3",
"port": "o4"
},
"B5/drive_lo": {
"instrument": "octave3",
"port": "o3"
},
"D1/drive_lo": {
"instrument": "octave5",
"port": "o2"
},
"D2D3/drive_lo": {
"instrument": "octave5",
"port": "o4"
},
"A/probe_lo": {
"instrument": "octave4",
"port": "o1"
},
"B/probe_lo": {
"instrument": "octave2",
"port": "o1"
},
"D/probe_lo": {
"instrument": "octave5",
"port": "o1"
},
"A1/flux": {
"instrument": "con7",
"port": "o3"
},
"A2/flux": {
"instrument": "con7",
"port": "o4"
},
"A3/flux": {
"instrument": "con7",
"port": "o5"
},
"A4/flux": {
"instrument": "con7",
"port": "o6"
},
"A5/flux": {
"instrument": "con7",
"port": "o7"
},
"A6/flux": {
"instrument": "con7",
"port": "o8"
},
"B1/flux": {
"instrument": "con4",
"port": "o1"
},
"B2/flux": {
"instrument": "con4",
"port": "o2"
},
"B3/flux": {
"instrument": "con4",
"port": "o3"
},
"B4/flux": {
"instrument": "con4",
"port": "o4"
},
"B5/flux": {
"instrument": "con4",
"port": "o5"
},
"D1/flux": {
"instrument": "con9",
"port": "o3"
},
"D2/flux": {
"instrument": "con9",
"port": "o4"
},
"D3/flux": {
"instrument": "con9",
"port": "o5"
},
"D4/flux": {
"instrument": "con9",
"port": "o6"
},
"D5/flux": {
"instrument": "con9",
"port": "o7"
},
"A1/acquisition": {
"instrument": "con5",
"port": "i1"
},
"A2/acquisition": {
"instrument": "con5",
"port": "i1"
},
"A3/acquisition": {
"instrument": "con5",
"port": "i1"
},
"A4/acquisition": {
"instrument": "con5",
"port": "i1"
},
"A5/acquisition": {
"instrument": "con5",
"port": "i1"
},
"A6/acquisition": {
"instrument": "con5",
"port": "i1"
},
"B1/acquisition": {
"instrument": "con2",
"port": "i1"
},
"B2/acquisition": {
"instrument": "con2",
"port": "i1"
},
"B3/acquisition": {
"instrument": "con2",
"port": "i1"
},
"B4/acquisition": {
"instrument": "con2",
"port": "i1"
},
"B5/acquisition": {
"instrument": "con2",
"port": "i1"
},
"D1/acquisition": {
"instrument": "con6",
"port": "i1"
},
"D2/acquisition": {
"instrument": "con6",
"port": "i1"
},
"D3/acquisition": {
"instrument": "con6",
"port": "i1"
},
"D4/acquisition": {
"instrument": "con6",
"port": "i1"
},
"D5/acquisition": {
"instrument": "con6",
"port": "i1"
}
}
}
Loading

0 comments on commit adb77d1

Please sign in to comment.