3
3
from beartype import beartype
4
4
from beartype .typing import TYPE_CHECKING , Any , Dict , List , Union , Optional
5
5
6
+ from bloqade .analog .ir .scalar import Variable
6
7
from bloqade .analog .builder .typing import ScalarType
8
+ from bloqade .analog .builder .pragmas import Assignable
7
9
from bloqade .analog .ir .routine .base import Routine
8
10
from bloqade .analog .ir .control .waveform import Linear , Constant , Waveform
9
11
@@ -92,12 +94,12 @@ def piecewise_linear(durations: List[ScalarType], values: List[ScalarType]) -> W
92
94
"The length of values must be one greater than the length of durations"
93
95
)
94
96
95
- pwl_wf = None
96
- for duration , start , stop in zip ( durations , values [: - 1 ], values [ 1 :]):
97
- if pwl_wf is None :
98
- pwl_wf = Linear (start , stop , duration )
99
- else :
100
- pwl_wf = pwl_wf .append (Linear (start , stop , duration ))
97
+ if len ( durations ) == 0 :
98
+ raise ValueError ( "The durations and values lists must not be empty." )
99
+
100
+ pwl_wf = Linear (values [ 0 ], values [ 1 ], durations [ 0 ] )
101
+ for duration , start , stop in zip ( durations [ 1 :], values [ 1 : - 1 ], values [ 2 :]) :
102
+ pwl_wf = pwl_wf .append (Linear (start , stop , duration ))
101
103
102
104
return pwl_wf
103
105
@@ -128,12 +130,12 @@ def piecewise_constant(
128
130
"The length of values must be the same as the length of durations"
129
131
)
130
132
131
- pwc_wf = None
132
- for duration , value in zip ( durations , values ):
133
- if pwc_wf is None :
134
- pwc_wf = Constant (value , duration )
135
- else :
136
- pwc_wf = pwc_wf .append (Constant (value , duration ))
133
+ if len ( durations ) == 0 :
134
+ raise ValueError ( "The durations and values lists must not be empty." )
135
+
136
+ pwc_wf = Constant (values [ 0 ], durations [ 0 ] )
137
+ for duration , value in zip ( durations [ 1 :], values [ 1 :]) :
138
+ pwc_wf = pwc_wf .append (Constant (value , duration ))
137
139
138
140
return pwc_wf
139
141
@@ -146,7 +148,7 @@ def rydberg_h(
146
148
phase : Optional [Waveform ] = None ,
147
149
static_params : Dict [str , Any ] = {},
148
150
batch_params : Union [List [Dict [str , Any ]], Dict [str , Any ]] = [],
149
- args : List [str ] = [],
151
+ args : List [str | Variable ] = [],
150
152
) -> Routine :
151
153
"""Create a rydberg program with uniform detuning, amplitude, and phase.
152
154
@@ -181,10 +183,15 @@ def rydberg_h(
181
183
prog = prog .rydberg .detuning .uniform .apply (detuning )
182
184
183
185
if amplitude is not None :
184
- prog = prog .amplitude .uniform .apply (amplitude )
186
+ prog = prog .rydberg . rabi . amplitude .uniform .apply (amplitude )
185
187
186
188
if phase is not None :
187
- prog = prog .phase .uniform .apply (phase )
189
+ prog = prog .rydberg .rabi .phase .uniform .apply (phase )
190
+
191
+ if not isinstance (prog , Assignable ):
192
+ raise ValueError (
193
+ "At least one of detuning, amplitude, or phase must be provided."
194
+ )
188
195
189
196
prog = prog .assign (** static_params )
190
197
0 commit comments