Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Tag q1asm instruction on serialization and validation
Browse files Browse the repository at this point in the history
alecandido committed Dec 9, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent f96588c commit e04d589
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/qibolab/_core/instruments/qblox/ast_.py
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
from pydantic import (
AfterValidator,
BeforeValidator,
ConfigDict,
computed_field,
field_validator,
model_serializer,
@@ -60,9 +61,32 @@ def dump(self) -> str:


class Instr(Model):
model_config = ConfigDict(extra="ignore")

@model_validator(mode="before")
@classmethod
def load(cls, data: Any) -> Any:
"""Leverage automated tagging to resolve conflicts.
This is required to unambiguously deserialize the instruction. Cf.
:meth:`instr`.
It is kind of surrogate of Pyantic's discriminated unions, without the need of
manually labeling each class, since the label is derived from the type.
"""
if "instr" in data:
assert data["instr"] == cls.keyword()
return data

@computed_field
@property
def instr(self) -> str:
"""Store instruction information in the serialization.
The instruction is non-uniquely identified by the attributes
structure, thus logging its identity is required, but the
information at runtime is only contained in the model's type.
"""
return self.keyword()

@classmethod

0 comments on commit e04d589

Please sign in to comment.