Skip to content

Commit

Permalink
fix(py): Waveforms implement constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
MarquessV committed Nov 21, 2024
1 parent cbe1f42 commit 526d1e3
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 0 deletions.
113 changes: 113 additions & 0 deletions quil-py/src/waveforms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,35 @@ impl_into_iq_values!(PyErfSquare);
impl_repr!(PyErfSquare);
impl_eq!(PyErfSquare);

#[pymethods]
impl PyErfSquare {
#[new]
#[allow(clippy::too_many_arguments)]
fn __new__(
duration: f64,
risetime: f64,
sample_rate: f64,
pad_left: f64,
pad_right: f64,
positive_polarity: bool,
scale: f64,
phase: f64,
detuning: f64,
) -> Self {
PyErfSquare(ErfSquare {
duration,
risetime,
sample_rate,
pad_left,
pad_right,
positive_polarity,
scale,
phase,
detuning,
})
}
}

py_wrap_data_struct! {
#[derive(Debug, PartialEq)]
#[pyo3(subclass)]
Expand All @@ -126,6 +155,30 @@ impl_into_iq_values!(PyGaussian);
impl_repr!(PyGaussian);
impl_eq!(PyGaussian);

#[pymethods]
impl PyGaussian {
#[new]
fn __new__(
duration: f64,
fwhm: f64,
t0: f64,
sample_rate: f64,
scale: f64,
phase: f64,
detuning: f64,
) -> Self {
PyGaussian(Gaussian {
duration,
fwhm,
t0,
sample_rate,
scale,
phase,
detuning,
})
}
}

py_wrap_data_struct! {
#[derive(Debug, PartialEq)]
#[pyo3(subclass)]
Expand All @@ -145,6 +198,35 @@ impl_into_iq_values!(PyDragGaussian);
impl_repr!(PyDragGaussian);
impl_eq!(PyDragGaussian);

#[pymethods]
impl PyDragGaussian {
#[new]
#[allow(clippy::too_many_arguments)]
fn __new__(
duration: f64,
fwhm: f64,
t0: f64,
anh: f64,
alpha: f64,
sample_rate: f64,
scale: f64,
phase: f64,
detuning: f64,
) -> Self {
PyDragGaussian(DragGaussian {
duration,
fwhm,
t0,
anh,
alpha,
sample_rate,
scale,
phase,
detuning,
})
}
}

py_wrap_data_struct! {
#[derive(Debug, PartialEq)]
#[pyo3(subclass)]
Expand All @@ -164,3 +246,34 @@ py_wrap_data_struct! {
impl_into_iq_values!(PyHermiteGaussian);
impl_repr!(PyHermiteGaussian);
impl_eq!(PyHermiteGaussian);

#[pymethods]
impl PyHermiteGaussian {
#[allow(clippy::too_many_arguments)]
#[new]
fn __new__(
duration: f64,
fwhm: f64,
t0: f64,
anh: f64,
alpha: f64,
sample_rate: f64,
second_order_hrm_coeff: f64,
scale: f64,
phase: f64,
detuning: f64,
) -> Self {
PyHermiteGaussian(HermiteGaussian {
duration,
fwhm,
t0,
anh,
alpha,
sample_rate,
second_order_hrm_coeff,
scale,
phase,
detuning,
})
}
}
24 changes: 24 additions & 0 deletions quil-py/tests_py/test_waveform.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from quil.waveforms import ErfSquare, BoxcarKernel, apply_phase_and_detuning, DragGaussian, Gaussian, HermiteGaussian


def test_apply_phase_and_detuning():
iq_values = [1.0, 0.0, 1.0, 0.0]
apply_phase_and_detuning(iq_values, 0, 0, 44100)
assert iq_values == [0, 0, 0, 0]


class TestConstrutor:
def test_boxcar_kernel(self):
BoxcarKernel(0.0, 0.0, 0.0)

def test_erf_square(self):
ErfSquare(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)

def test_gaussian(self):
Gaussian(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)

def test_drag_gaussian(self):
DragGaussian(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)

def test_hermite_gaussian(self):
DragGaussian(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)

0 comments on commit 526d1e3

Please sign in to comment.