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

Serialization blockers #882

Closed
11 of 14 tasks
alecandido opened this issue Apr 23, 2024 · 0 comments · Fixed by #971
Closed
11 of 14 tasks

Serialization blockers #882

alecandido opened this issue Apr 23, 2024 · 0 comments · Fixed by #971
Milestone

Comments

@alecandido
Copy link
Member

alecandido commented Apr 23, 2024

My current intention was to start from the Pulses, and propagate Pydantic to the other classes involved in serialize.py, to eventually drop the custom functions, manipulating the various objects.

While inspecting serializing.py, I'm finding a few limitations that makes it impractical to just follow this plan, without taking care at the same time of other aspects involved.

  • _load_pulse is almost fully converted, but for couplers
    _PulseLike = TypeAdapter(PulseLike, config=ConfigDict(extra="ignore"))
    """Parse a pulse-like object.
    .. note::
    Extra arguments are ignored, in order to standardize the qubit handling, since the
    :cls:`Delay` object has no `qubit` field.
    This will be removed once there won't be any need for dedicated couplers handling.
    """
    def _load_pulse(pulse_kwargs: dict, qubit: Qubit):
    coupler = "coupler" in pulse_kwargs
    pulse_kwargs["qubit"] = pulse_kwargs.pop(
    "coupler" if coupler else "qubit", qubit.name
    )
    return _PulseLike.validate_python(pulse_kwargs)
  • _load_single_qubit_natives should not present any further complication (beyond full _load_pulse conversion)
  • _load_two_qubit_natives is also dealing with couplers explicitly, and converting one-element's sequences
  • register_gates is also dealing with couplers explicitly, and with qubit names (it requires json.loads to deserialize integers and strings at the same time), and similar shenanigans are involved for the qubit pair names, and extra handling for symmetric gates
  • _dump_pulse is taking the burden of deleting a bunch of things
    if pulse.type in (PulseType.FLUX, PulseType.COUPLERFLUX):
    del data["frequency"]
    data["type"] = data["type"].value
    if "channel" in data:
    del data["channel"]
    if "relative_phase" in data:
    del data["relative_phase"]

    and it is also explicitly converting the enum variants to the values (that I suspect being wrong, since already done by Pydantic, so most likely it's not properly tested)
  • _dump_single_qubit_natives is deleting the .qubit attribute
  • _dump_two_qubit_natives is dealing with couplers explicitly, and it's also filtering 0-length sequences
  • dump_native_gates is dealing with couplers explicitly, filtering 0-length sequences, and constructing the pair name

Thus, to advance this PR, it would be nice to:

  • improve couplers handling Remove couplers #891
    • they are essentially everywhere, and you always have to check manually if you want to target a qubit or a coupler, and then do the exact same thing
    • we should treat couplers as regular qubits, or inherit both from the same object
  • standardize qubit names
    • I still would like to restrict to integers, and keep a mapping somewhere else (if in Qibolab as well, fully external)
    • Pydantic could handle the Union for us (but I'd suggest avoiding)
  • same for pairs identifiers
  • symmetric gates should not be duplicated on load, but the lookup process should realize it is symmetric, and check for the sorted one (or check for a random one, and fallback on the other)
  • 0-length sequences should be left where they are (if you don't want to serialize, do not add to the platform at all) and 1-length sequences should be treated as sequences, and not converted to elements
  • pulse attributes should be serialized as they are, without manual deletions
    • if there are fields that should not be there when serializing, maybe they shouldn't be there at all
    • Channel api #885 should help with this

Originally posted by @alecandido in #870 (comment)

A discussion about couplers is in the following comments #870 (comment), with a proposal on how to deal with them #870 (comment).

@alecandido alecandido added this to the Qibolab 0.2.0 milestone Apr 23, 2024
@alecandido alecandido linked a pull request Aug 13, 2024 that will close this issue
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant