Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Circuit serialization as parameters of the tomography #1002

Merged
merged 3 commits into from
Oct 14, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/qibocal/auto/task.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
"""Action execution tracker."""

import copy
import json
from dataclasses import asdict, dataclass
from pathlib import Path
from typing import Any, NewType, Optional, Union

import yaml
from qibo import Circuit
from qibolab.platform import Platform
from qibolab.qubits import QubitId, QubitPairId

Expand All @@ -21,6 +23,7 @@
"""Elements to be calibrated by a single protocol."""

SINGLE_ACTION = "action.yml"
CIRCUIT = "circuit.json"


@dataclass
Expand All @@ -40,6 +43,13 @@ class Action:

def dump(self, path: Path):
"""Dump single action to yaml."""
if self.parameters is not None:
for param, value in self.parameters.items():
if type(value) is Circuit:
circuit_path = path / CIRCUIT
circuit_file = open(circuit_path, "w")
json.dump(value.raw, circuit_file)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either use with open(...) as fd: or use circuit_file.write_text(json.dumps(...)). You should close file descriptors, and better doing it automatically than manually.

self.parameters[param] = str(circuit_path)
(path / SINGLE_ACTION).write_text(yaml.safe_dump(asdict(self)))

@classmethod
Expand Down