Skip to content

Commit

Permalink
feat: measure element duration (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
kahojyun authored Jul 5, 2024
1 parent 68d1e61 commit 5a72668
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions bosing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class Element:
def max_duration(self) -> float: ...
@property
def min_duration(self) -> float: ...
def measure(self) -> float: ...

@final
class Play(Element):
Expand Down
7 changes: 7 additions & 0 deletions docs/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,10 @@

.. plot:: ../example/flexible.py
:include-source:


获取 `Element` 长度
-------------------

.. plot:: ../example/flexible_length.py
:include-source:
22 changes: 22 additions & 0 deletions example/flexible_length.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import matplotlib.pyplot as plt

from bosing import Channel, Hann, Play, Stack, generate_waveforms

sample_rate = 2e9
schedule = Stack(
Play(
channel_id="xy",
shape_id="hann",
amplitude=0.3,
width=100e-9,
plateau=200e-9,
),
margin=10e-9,
)
channels = {"xy": Channel(30e6, sample_rate, int(sample_rate * schedule.measure()))}
shapes = {"hann": Hann()}
result = generate_waveforms(channels, shapes, schedule)
w = result["xy"]
plt.plot(w[0], label="I")
plt.plot(w[1], label="Q")
plt.legend()
7 changes: 6 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::{
Sampler,
},
quant::{Amplitude, ChannelId, Frequency, Phase, ShapeId, Time},
schedule::{ElementCommonBuilder, ElementRef},
schedule::{ElementCommonBuilder, ElementRef, Measure},
};

/// Channel configuration.
Expand Down Expand Up @@ -452,6 +452,11 @@ impl Element {
fn min_duration(&self) -> Time {
self.0.common.min_duration()
}

/// Measure the minimum duration of the element.
fn measure(&self) -> Time {
self.0.measure()
}
}

trait ElementSubclass: Sized + DerefToPyAny
Expand Down

0 comments on commit 5a72668

Please sign in to comment.