-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #758 from qiboteam/kernel
Kernel class
- Loading branch information
Showing
24 changed files
with
304 additions
and
106 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .platform import create_dummy |
Binary file not shown.
File renamed without changes.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import json | ||
from pathlib import Path | ||
|
||
import numpy as np | ||
|
||
from qibolab.qubits import QubitId | ||
|
||
KERNELS = "kernels.npz" | ||
|
||
|
||
class Kernels(dict[QubitId, np.ndarray]): | ||
"""A dictionary subclass for handling Qubit Kernels. | ||
This class extends the built-in dict class and maps QubitId to numpy | ||
arrays. It provides methods to load and dump the kernels from and to | ||
a file. | ||
""" | ||
|
||
@classmethod | ||
def load(cls, path: Path): | ||
"""Class method to load kernels from a file. | ||
The file should contain a serialized dictionary where keys are | ||
serialized QubitId and values are numpy arrays. | ||
""" | ||
return cls( | ||
{json.loads(key): value for key, value in np.load(path / KERNELS).items()} | ||
) | ||
|
||
def dump(self, path: Path): | ||
"""Instance method to dump the kernels to a file. | ||
The keys (QubitId) are serialized to strings and the values | ||
(numpy arrays) are kept as is. | ||
""" | ||
np.savez( | ||
path / KERNELS, | ||
**{json.dumps(qubit_id): value for qubit_id, value in self.items()} | ||
) |
Oops, something went wrong.