Skip to content

Commit

Permalink
fix: Refactor kernel saving and loading
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacfomg committed Jan 17, 2024
1 parent e8c1b8d commit d3619f4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/qibolab/kernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ def dump(self, path: Path):
The keys (QubitId) are serialized to strings and the values
(numpy arrays) are kept as is.
"""
np.savez(path, **{json.dumps(key): value for key, value in self.items()})
np.savez(
path, **{json.dumps(qubit_id): value for qubit_id, value in self.items()}
)
10 changes: 6 additions & 4 deletions src/qibolab/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
)
from qibolab.qubits import Qubit, QubitPair

KERNELS_FILE = "kernels.npz"


def load_runcard(path: Path) -> dict:
"""Load runcard YAML to a dictionary."""
Expand Down Expand Up @@ -51,7 +53,7 @@ def load_qubits(
}

if extras_folder is not None:
kernels = Kernels.load(path=extras_folder / "kernels.npz")
kernels = Kernels.load(path=extras_folder / KERNELS_FILE)
for q in kernels:
qubits[q].kernel = kernels[q]

Expand Down Expand Up @@ -178,12 +180,12 @@ def dump_runcard(platform: Platform, path: Path):
path (pathlib.Path): Path that the yaml file will be saved.
"""

kernels = {}
kernels = Kernels()
for qubit in platform.qubits.values():
if qubit.kernel is not None:
kernels[str(qubit.name)] = qubit.kernel
kernels[qubit.name] = qubit.kernel
qubit.kernel = None
Kernels(kernels).dump(Path(__file__).parent / "dummy/kernels.npz")
Kernels(kernels).dump(Path(__file__).parent / "dummy" / KERNELS_FILE)

settings = {
"nqubits": platform.nqubits,
Expand Down
4 changes: 2 additions & 2 deletions tests/dummy_qrc/zurich.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ def create(runcard_path=RUNCARD):
channels[ch].local_oscillator = local_oscillators[lo]

# create qubit objects
runcard = load_runcard(runcard_path, FOLDER)
qubits, couplers, pairs = load_qubits(runcard)
runcard = load_runcard(runcard_path)
qubits, couplers, pairs = load_qubits(runcard, FOLDER)
settings = load_settings(runcard)

# assign channels to qubits and sweetspots(operating points)
Expand Down

0 comments on commit d3619f4

Please sign in to comment.