Closed anton-buyskikh closed 1 month ago
Hi @anton-buyskikh I would say this is a perfect bug report!
It seems the issue arises when using the pipe operator rather than e.g. Optional[int]
, it turns out that in this case the type origin is types.UnionType
rather than typing.Union
. I have fixed this in PR #47
Thanks for submitting this! And feel free to reach out if you need help with anything
@nulinspiratie thanks for a quick response, I'll give it try soon! Just wanted to add that issue might have been still relevant for other standard datatypes, like float, complex, bool, str, list, ...
I haven't checked them yet.
It's more of a question rather than a bug report. I'd like to understanding what is the intended way or working with optional attributes in
quam_dataclass
.For instance, if a new attribute
param_x: int | None = None
is added to the Transmon class in your example https://github.com/qua-platform/quam/blob/c24f3642dfb4609923f50fc13dbe19818c9c527a/quam/examples/superconducting_qubits/components.py#L12 thengenerate_superconducting_quam.py
works just fine. The defaultNone
is serialised/deserialised successfully. It also works successfully with eitherinclude_defaults
flag inQuAM.save
.However, if I provide a integer value on initialisation and rerun
generate_superconducting_quam.py
the following error is raised:TypeError: Instantiation for type int | None in QuAM.qubits["q0"].param_x not implemented
.It seems like this error is raised only for primitive types, and if I correct the type in line https://github.com/qua-platform/quam/blob/c24f3642dfb4609923f50fc13dbe19818c9c527a/quam/examples/superconducting_qubits/components.py#L17 to optional, such as
xy: IQChannel | None = None
then the deserialisation works fine.