Skip to content

Commit

Permalink
fix: Propagate Pydantic models to Pulse
Browse files Browse the repository at this point in the history
  • Loading branch information
alecandido committed Mar 21, 2024
1 parent 1006d87 commit 57b9da7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
4 changes: 1 addition & 3 deletions src/qibolab/instruments/qm/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
import numpy as np
from qibo.config import raise_error

from qibolab.pulses import Envelopes, PulseType
from qibolab.pulses import PulseType, Rectangular

from .ports import OPXIQ, OctaveInput, OctaveOutput

Rectangular = Envelopes.RECTANGULAR.value

SAMPLING_RATE = 1
"""Sampling rate of Quantum Machines OPX in GSps."""

Expand Down
21 changes: 13 additions & 8 deletions src/qibolab/pulses/pulse.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""Pulse class."""

from dataclasses import dataclass, fields
from dataclasses import fields
from enum import Enum
from typing import Optional

import numpy as np
from pydantic import BaseModel

from .envelope import Envelope, IqWaveform, Times, Waveform

Expand All @@ -23,9 +24,7 @@ class PulseType(Enum):
COUPLERFLUX = "cf"


# TODO: replace nested serialization with pydantic
@dataclass
class Pulse:
class Pulse(BaseModel):
"""A class to represent a pulse to be sent to the QPU."""

start: int
Expand Down Expand Up @@ -64,10 +63,16 @@ class Pulse:
"""Qubit or coupler addressed by the pulse."""

@classmethod
def flux(cls, start, duration, amplitude, envelope, **kwargs):
return cls(
start, duration, amplitude, 0, 0, envelope, type=PulseType.FLUX, **kwargs
)
def flux(cls, **kwargs):
"""Construct a flux pulse.
It provides a simplified syntax for the :cls:`Pulse` constructor, by applying
suitable defaults.
"""
kwargs["frequency"] = 0
kwargs["relative_phase"] = 0
kwargs["type"] = PulseType.FLUX
return cls(**kwargs)

@property
def finish(self) -> Optional[int]:
Expand Down

0 comments on commit 57b9da7

Please sign in to comment.