Skip to content

take_bias_steps fails and hits UnboundLocalError #395

@BrianJKoopman

Description

@BrianJKoopman

From a crash last night on satp1 it looks like operations.bias_steps.take_bias_steps sometimes fails in this try block and hits an UnboundLocalError due to the variable init_current_mode not being set when an exception is raised during the try:

try:
dc_biases = initial_dc_biases
init_current_mode = sdl.get_current_mode_array(S)
if high_current_mode:
dc_biases = dc_biases / S.high_low_current_ratio
step_voltage /= S.high_low_current_ratio
sdl.set_current_mode(S, bgs, 1)
S.log(f"Waiting {hcm_wait_time} sec after switching to hcm")
time.sleep(hcm_wait_time)
bsa = BiasStepAnalysis(S, cfg, bgs, run_kwargs=run_kwargs)
bsa.sid = sdl.stream_g3_on(
S, tag=g3_tag, channel_mask=channel_mask, downsample_factor=1,
filter_disable=True, subtype=stream_subtype, enable_compression=enable_compression
)
bsa.start = time.time()
for bg in bgs:
if use_waveform:
play_bias_steps_waveform(
S, cfg, bg, step_duration, step_voltage,
num_steps=nsteps
)
else:
play_bias_steps_dc(
S, cfg, bg, step_duration, step_voltage,
num_steps=nsteps, dacs=dacs,
)
bsa.stop = time.time()
finally:
sdl.stream_g3_off(S)
# Restores current mode to initial values
sdl.set_current_mode(S, np.where(init_current_mode == 0)[0], 0)
sdl.set_current_mode(S, np.where(init_current_mode == 1)[0], 1)
S.set_downsample_factor(initial_ds_factor)
S.set_filter_disable(initial_filter_disable)

The full traceback:

Traceback (most recent call last):
  File "<string>", line 30, in <module>
  File "/usr/local/lib/python3.10/dist-packages/sorunlib/smurf.py", line 209, in take_bgmap
    check_response(resp)
  File "/usr/local/lib/python3.10/dist-packages/sorunlib/_internal.py", line 35, in check_response
    raise RuntimeError(error)
RuntimeError: Task failed to complete successfully.
OCSReply: OK : Operation "take_bgmap" is currently not running (FAILED).
  take_bgmap[session=541]; status=done with ERROR 61.2 s ago, took 4.6 s
  messages (4 of 4):
    1698922951.696 Status is now "starting".
    1698922951.699 Status is now "running".
    1698922956.276 CRASH: [Failure instance: Traceback: <class 'UnboundLocalError'>: local variable 'init_current_mode' referenced before assignment
/usr/lib/python3.8/threading.py:932:_bootstrap_inner
/usr/lib/python3.8/threading.py:870:run
/usr/local/lib/python3.8/dist-packages/twisted/_threads/_threadworker.py:47:work
/usr/local/lib/python3.8/dist-packages/twisted/_threads/_team.py:182:doWork
--- <exception caught here> ---
/usr/local/lib/python3.8/dist-packages/twisted/python/threadpool.py:244:inContext
/usr/local/lib/python3.8/dist-packages/twisted/python/threadpool.py:260:<lambda>
/usr/local/lib/python3.8/dist-packages/twisted/python/context.py:117:callWithContext
/usr/local/lib/python3.8/dist-packages/twisted/python/context.py:82:callWithContext
/usr/local/lib/python3.8/dist-packages/socs/agents/pysmurf_controller/agent.py:654:take_bgmap
/usr/local/src/pysmurf/python/pysmurf/client/util/pub.py:50:wrapper
/sodetlib/sodetlib/operations/bias_steps.py:1067:take_bgmap
/usr/local/src/pysmurf/python/pysmurf/client/util/pub.py:50:wrapper
/sodetlib/sodetlib/operations/bias_steps.py:1205:take_bias_steps
]
    1698922956.284 Status is now "done".
  other keys in .session: op_code, data

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions