Commit 0a116ef8 authored by Damien Crielaard's avatar Damien Crielaard
Browse files

Merge branch 'changes-dc-compensation-pulse' into 'develop'

Improvement DCCompensation Pulse

See merge request !183
parents ce3e7dc2 5236e4f3
Loading
Loading
Loading
Loading
Loading
+72 −67
Original line number Diff line number Diff line
@@ -484,7 +484,15 @@ class DRAGPulse(Operation):
        return self._get_signature(pulse_info)


class DCCompensationPulse(SquarePulse):
def create_dc_compensation_pulse(
    pulses: List[Operation],
    sampling_rate: int,
    port: str,
    t0: float = 0,
    amp: Optional[float] = None,
    duration: Optional[float] = None,
    data: Optional[Dict[str, Any]] = None,
) -> SquarePulse:
    """
    Calculates a SquarePulse to counteract charging effects based on a list of pulses.

@@ -492,6 +500,9 @@ class DCCompensationPulse(SquarePulse):
    ----------
    pulses
        List of pulses to compensate
    sampling_rate
        Resolution to calculate the enclosure of the
        pulses to calculate the area to compensate.
    amp
        Desired amplitude of the DCCompensationPulse.
        Leave to None to calculate the value for compensation,
@@ -518,24 +529,18 @@ class DCCompensationPulse(SquarePulse):
        The operation's dictionary, by default None
        Note: if the data parameter is not None all other parameters are
        overwritten using the contents of data.
    """

    def __init__(
        self,
        pulses: List[Operation],
        sampling_rate: int,
        port: str,
        t0: float = 0,
        amp: Optional[float] = None,
        duration: Optional[float] = None,
        data: Optional[Dict[str, Any]] = None,
    ) -> None:
    Returns
    -------

    :
        Returns a SquarePulse object that compensates all pulses passed as
        argument
    """
    # Make sure that the list contains at least one element
    assert len(pulses) > 0

        pulse_info_list: List[Dict[str, Any]] = DCCompensationPulse._extract_pulses(
            pulses, port
        )
    pulse_info_list: List[Dict[str, Any]] = _extract_pulses(pulses, port)

    # Calculate the area given by the list of pulses
    area: float = area_pulses(pulse_info_list, sampling_rate)
@@ -552,14 +557,14 @@ class DCCompensationPulse(SquarePulse):
            c_amp = -abs(amp)
        else:
            c_amp = abs(amp)
            c_duration = area / c_amp
        c_duration = abs(area / c_amp)
    else:
        raise ValueError(
            "The `DCCompensationPulse` allows either amp or duration to "
            + "be specified, not both. Both amp and duration were passed."
        )

        super().__init__(
    return SquarePulse(
        amp=c_amp,
        duration=c_duration,
        port=port,
@@ -569,7 +574,7 @@ class DCCompensationPulse(SquarePulse):
        data=data,
    )

    @staticmethod

def _extract_pulses(pulses: List[Operation], port: str) -> List[Dict[str, Any]]:
    # Collect all pulses for the given port
    pulse_info_list: List[Dict[str, Any]] = list()
+7 −5
Original line number Diff line number Diff line
@@ -13,8 +13,8 @@ from quantify_scheduler.pulse_library import (
    RampPulse,
    SoftSquarePulse,
    SquarePulse,
    create_dc_compensation_pulse,
    decompose_long_square_pulse,
    DCCompensationPulse,
)

from quantify_scheduler.resources import BasebandClockResource, ClockResource
@@ -246,7 +246,7 @@ def test_dccompensation_pulse_amp() -> None:
        amp=1, duration=1e-8, port="LP", clock=BasebandClockResource.IDENTITY
    )

    pulse2 = DCCompensationPulse(
    pulse2 = create_dc_compensation_pulse(
        duration=1e-8,
        pulses=[pulse0, pulse1],
        sampling_rate=int(1e9),
@@ -259,7 +259,9 @@ def test_dccompensation_pulse_modulated() -> None:
    clock = ClockResource("clock", 1.0)
    pulse0 = SquarePulse(amp=1, duration=1e-8, port="LP", clock=clock)
    with pytest.raises(ValueError):
        DCCompensationPulse(amp=1, pulses=[pulse0], port="LP", sampling_rate=int(1e9))
        create_dc_compensation_pulse(
            amp=1, pulses=[pulse0], port="LP", sampling_rate=int(1e9)
        )


def test_dccompensation_pulse_duration() -> None:
@@ -270,7 +272,7 @@ def test_dccompensation_pulse_duration() -> None:
        amp=1, duration=1e-8, port="LP", clock=BasebandClockResource.IDENTITY
    )

    pulse2 = DCCompensationPulse(
    pulse2 = create_dc_compensation_pulse(
        amp=1,
        pulses=[pulse0, pulse1],
        sampling_rate=int(1e9),
@@ -285,7 +287,7 @@ def test_dccompensation_pulse_both_params() -> None:
        pulse0 = SquarePulse(
            amp=1, duration=1e-8, port="LP", clock=BasebandClockResource.IDENTITY
        )
        DCCompensationPulse(
        create_dc_compensation_pulse(
            amp=1,
            duration=1e-8,
            pulses=[pulse0],