Skip to content

Boolean parameter values deserialize as floats during restoration #152

Description

@marcosfrenkel

This was generated by AI during triage.

Summary

Boolean parameter values sent through the JSON wire protocol are deserialized as floats. This prevents Client.paramsFromFile() and Client.setParameters() from restoring QCoDeS parameters that use a Boolean validator.

Current behavior

False and True become 0.0 and 1.0 respectively during encode()/decode(). When the Server applies the value, QCoDeS rejects it because a float is not Boolean. The error is logged and swallowed by parameter restoration, leaving the parameter unchanged.

Minimal reproduction:

instruction = ServerInstruction(
    operation=Operation.set_params,
    set_parameters={"generator.rf_on": False},
)

decoded = decode(encode(instruction))
assert decoded.set_parameters["generator.rf_on"] is False

The assertion currently fails because the decoded value is 0.0.

An end-to-end reproduction is to save an instrument whose Boolean parameter is True, change it to False, and call Client.paramsFromFile(). Numeric parameters are restored, but the Boolean parameter remains False.

Cause

deserialize_obj() attempts numeric conversion before preserving native JSON booleans. Since Python booleans are numeric-compatible, _is_numeric(False) and _is_numeric(True) return 0.0 and 1.0.

Desired behavior

Native JSON booleans must remain bool values throughout wire deserialization. Existing handling for numeric values and the string forms "True" and "False" must continue to work.

Acceptance criteria

  • False round-trips through encode()/decode() as False, with type bool.
  • True round-trips through encode()/decode() as True, with type bool.
  • Client.setParameters() can set a Boolean QCoDeS parameter.
  • Client.paramsFromFile() restores Boolean and numeric parameters from the same file.
  • Existing serialization, networking, and parameter-persistence tests continue to pass.

Out of scope

  • Changing the flat dictionary format accepted by Client.setParameters().
  • Making nested paramsToFile() output directly acceptable to Client.setParameters(); Client.paramsFromFile() already performs that flattening.

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