Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add early validation for setpoint parameters in follow_param()#38

Closed
Copilot wants to merge 3 commits intomasterfrom
copilot/improve-error-message-setpoint-params
Closed

Add early validation for setpoint parameters in follow_param()#38
Copilot wants to merge 3 commits intomasterfrom
copilot/improve-error-message-setpoint-params

Conversation

Copy link
Contributor

Copilot AI commented Jan 28, 2026

Users attempting to follow setpoint parameters (the swept parameter itself) received cryptic ValueError: Invalid dependencies from QCoDeS at measurement start. This occurred when users mistakenly called sweep.follow_param(voltage) where voltage was the setpoint being swept, creating a circular dependency that QCoDeS detected but reported unclearly.

Changes

BaseSweep.follow_param()

  • Validates parameter is not self.set_param before adding to _params
  • Raises clear ValueError explaining setpoints are auto-recorded as independent variables
  • Added _internal flag to bypass validation for internal use (Sweep2D outer parameter tracking)

Sweep2D.follow_param()

  • Validates against both self.in_param (inner) and self.set_param (outer) setpoints
  • Delegates to in_sweep.follow_param(..., _internal=True) for numeric parameter validation
  • Provides specific error messages distinguishing inner vs outer setpoint violations

Tests

  • Added 7 tests covering single parameters, lists, and both sweep types
  • Verifies rejection of non-numeric parameters through delegation

Example

Before:

sweep = Sweep1D(voltage, 0, 1, 0.1)
sweep.follow_param(voltage)
# ... later at measurement start:
# ValueError: Invalid dependencies

After:

sweep = Sweep1D(voltage, 0, 1, 0.1)
sweep.follow_param(voltage)
# ValueError: Cannot follow setpoint parameter 'voltage'.
# The setpoint parameter is automatically recorded as the independent variable.
# Only follow measured parameters (e.g., Lockin signals, voltmeters).
Original prompt

This section details on the original issue you should resolve

<issue_title>Improve error message when setpoint parameters are passed to follow_param</issue_title>
<issue_description>## Problem

When users include setpoint parameters (sweep parameters like B, T, Vtg, Vbg) in follow_param(), QCoDeS raises a cryptic error:

ValueError: Invalid dependencies

This error originates from QCoDeS' ParamSpecTree validation (dependency cycle detection) but gives no indication of what went wrong or how to fix it.

Feedback from AI agents (164 test runs)

This was one of the most common issues encountered (12 instances):

  • "Initial sweep attempt failed from dependency cycles when following setpoint parameters"
  • "ValueError: Invalid dependencies when follow_params included Vtg/Vbg (setpoint parameters)"
  • "Resolved by following only measured signals (Lockin_Ix, Lockin_Vx)"
  • "Initial init_database call failed (ValueError: ParamSpecTree cycles) when follow_param included setpoints"
  • "Reran sweep without following the setpoint"

Root Cause

In base_sweep.py, _create_measurement() registers followed parameters with setpoints:

for p in self._params:
    if self.set_param is None:
        self.meas.register_parameter(p, setpoints=("time",))
    else:
        self.meas.register_parameter(p, setpoints=(self.set_param,))

When the user follows the set_param itself, QCoDeS detects a circular dependency (parameter depends on itself as a setpoint).

Proposed Solution

Add validation in follow_param() to catch this early with a clear error message:

def follow_param(self, *p):
    """Saves parameters to be tracked, for both saving and plotting data."""
    for param in p:
        # Check for dependency cycle: can't follow the setpoint parameter
        if self.set_param is not None and param is self.set_param:
            raise ValueError(
                f"Cannot follow setpoint parameter '{param.name}'. "
                f"The setpoint parameter is automatically recorded as the independent variable. "
                f"Only follow measured parameters (e.g., Lockin signals, voltmeters)."
            )
        self._params.append(param)

For Sweep2D, also check against both inner and outer set_params.

Benefits

  • Clear, actionable error message instead of cryptic "Invalid dependencies"
  • Catches the error early (at follow_param call) instead of at measurement start
  • Educates users about the distinction between setpoints and measured parameters</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

- Add check in BaseSweep.follow_param() to raise clear error when users try to follow setpoint parameters
- Override follow_param() in Sweep2D to check both inner and outer setpoint parameters
- Add _internal flag to allow Sweep2D to internally follow outer parameter without triggering validation
- Add comprehensive tests in test_sweep_validation.py
- Error messages now clearly explain that setpoint parameters are automatically recorded

Co-authored-by: caidish <[email protected]>
@caidish caidish marked this pull request as ready for review January 28, 2026 22:31
- Delegate Sweep2D.follow_param to inner sweep to ensure numeric validation
- Add test assertion to verify params not added when error occurs
- Add test to verify Sweep2D properly rejects non-numeric parameters

Co-authored-by: caidish <[email protected]>
Copilot AI changed the title [WIP] Improve error message for setpoint parameters in follow_param Add early validation for setpoint parameters in follow_param() Jan 28, 2026
Copilot AI requested a review from caidish January 28, 2026 22:36
@caidish caidish closed this Feb 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve error message when setpoint parameters are passed to follow_param

2 participants