Skip to content

Commit 5e6166e

Browse files
author
Thomas Lemon
committed
Use gaurd to prevent division by zero error in _build_2d_script
1 parent 8e27fba commit 5e6166e

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

src/qcodes/instrument_drivers/Keithley/_Keithley_2600.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,34 @@ def _build_2d_script(self, config: _FastSweepConfig) -> list[str]:
296296
meas_channel = config.measurement_channel
297297
nplc = self.instrument.nplc()
298298

299+
assert config.inner_start is not None
300+
assert config.inner_stop is not None
301+
assert config.inner_npts is not None
299302
assert config.outer_start is not None
300303
assert config.outer_stop is not None
301304
assert config.outer_npts is not None
302305

303-
dX_inner = (config.inner_stop - config.inner_start) / (config.inner_npts - 1)
304-
dX_outer = (config.outer_stop - config.outer_start) / (config.outer_npts - 1)
306+
inner_npts = config.inner_npts
307+
outer_npts = config.outer_npts
308+
309+
if inner_npts < 1:
310+
raise ValueError("inner_npts must be at least 1 for 2D fast sweep.")
311+
if outer_npts < 1:
312+
raise ValueError("outer_npts must be at least 1 for 2D fast sweep.")
313+
314+
if inner_npts == 1:
315+
dX_inner = 0.0
316+
else:
317+
dX_inner = (config.inner_stop - config.inner_start) / (
318+
config.inner_npts - 1
319+
)
320+
321+
if outer_npts == 1:
322+
dX_outer = 0.0
323+
else:
324+
dX_outer = (config.outer_stop - config.outer_start) / (
325+
config.outer_npts - 1
326+
)
305327

306328
match config.mode:
307329
case "IV":

0 commit comments

Comments
 (0)