3939class EmulatorController (Controller ):
4040 """Emulator controller."""
4141
42+ sampling_rate_ : float = 1
43+ """Sampling rate used during simulation."""
4244 engine : SimulationEngine = QutipEngine ()
4345 """SimulationEngine. Default is QutipEngine."""
4446 bounds : str = "emulator/bounds"
47+ """Bounds for emulator."""
48+
49+ @property
50+ def sampling_rate (self ) -> float :
51+ return self .sampling_rate_
52+
53+ @sampling_rate .setter
54+ def sampling_rate (self , value : float ):
55+ self .sampling_rate_ = value
4556
4657 def connect (self ):
4758 """Dummy connect method."""
4859
4960 def disconnect (self ):
5061 """Dummy disconnect method."""
5162
52- @property
53- def sampling_rate (self ):
54- """Sampling rate of emulator."""
55- return 1
56-
5763 def play (
5864 self ,
5965 configs : dict [str , Config ],
@@ -127,7 +133,7 @@ def _play_sequence(
127133 the various measurements included in the sequence.
128134 """
129135 sequence_ = update_sequence (sequence , updates )
130- tlist_ = tlist (sequence_ , self .sampling_rate )
136+ tlist_ = tlist (sequence_ , self .sampling_rate , per_sample = 2 )
131137 configs_ = update_configs (configs , updates )
132138 config = cast (HamiltonianConfig , configs_ ["hamiltonian" ])
133139 hamiltonian = config .hamiltonian (config = configs_ , engine = self .engine )
@@ -151,8 +157,13 @@ def _pulse_hamiltonian(
151157 """Construct Hamiltonian time dependent term for qutip simulation."""
152158
153159 channels = [
154- [operator , channel_time (waveforms )]
155- for operator , waveforms in hamiltonians (sequence , configs , self .engine )
160+ [
161+ operator ,
162+ channel_time (waveforms , sampling_rate = self .sampling_rate ),
163+ ]
164+ for operator , waveforms in hamiltonians (
165+ sequence , configs , self .engine , self .sampling_rate
166+ )
156167 ]
157168 return OperatorEvolution (channels ) if len (channels ) > 0 else None
158169
@@ -206,21 +217,25 @@ def hamiltonian(
206217 hamiltonian : HamiltonianConfig ,
207218 hilbert_space_index : int ,
208219 engine : SimulationEngine ,
220+ sampling_rate : float ,
209221) -> tuple [Operator , list [Modulated ]]:
210222 n = hamiltonian .transmon_levels
211223 op = engine .expand (
212224 config .operator (n = n , engine = engine ), hamiltonian .dims , hilbert_space_index
213225 )
214226 waveforms = (
215- waveform (pulse , config , hamiltonian .qubits [hilbert_space_index ])
227+ waveform (pulse , config , hamiltonian .qubits [hilbert_space_index ], sampling_rate )
216228 for pulse in pulses
217229 if isinstance (pulse , (Pulse , Delay , VirtualZ ))
218230 )
219231 return (op , [w for w in waveforms if w is not None ])
220232
221233
222234def hamiltonians (
223- sequence : PulseSequence , configs : dict [str , Config ], engine : SimulationEngine
235+ sequence : PulseSequence ,
236+ configs : dict [str , Config ],
237+ engine : SimulationEngine ,
238+ sampling_rate : float ,
224239) -> Iterable [tuple [Operator , list [Modulated ]]]:
225240 hconfig = cast (HamiltonianConfig , configs ["hamiltonian" ])
226241 return (
@@ -230,14 +245,18 @@ def hamiltonians(
230245 hconfig ,
231246 index (ch , hconfig ),
232247 engine ,
248+ sampling_rate ,
233249 )
234250 for ch in sequence .channels
235251 # TODO: drop the following, and treat acquisitions just as empty channels
236252 if not isinstance (configs [ch ], AcquisitionConfig )
237253 )
238254
239255
240- def channel_time (waveforms : Iterable [Modulated ]) -> Callable [[float ], float ]:
256+ def channel_time (
257+ waveforms : Iterable [Modulated ],
258+ sampling_rate : int ,
259+ ) -> Callable [[float ], float ]:
241260 """Wrap time function for specific channel.
242261
243262 Used to avoid late binding issues.
@@ -247,13 +266,12 @@ def time(t: float) -> float:
247266 cumulative_time = 0
248267 cumulative_phase = 0
249268 for pulse in waveforms :
250- pulse_duration = pulse .duration # TODO: pass sampling rate
251269 pulse_phase = pulse .phase
252- if cumulative_time <= t < cumulative_time + pulse_duration :
270+ if cumulative_time <= t < cumulative_time + pulse . duration :
253271 relative_time = t - cumulative_time
254- index = int (relative_time ) # TODO: pass sampling rate
272+ index = int (np . floor ( relative_time * sampling_rate ))
255273 return pulse (t , index , cumulative_phase )
256- cumulative_time += pulse_duration
274+ cumulative_time += pulse . duration
257275 cumulative_phase += pulse_phase
258276 return 0
259277
0 commit comments