microsoft / microsoft/Qcodes

Dynamically changing val_mapping on existing parameters does not produce expected behaviour.

Open
#4,502 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
459
Forks
359
Avg merge
3d 6h
Merged PRs (30d)
73

Description

Dynamically changing val_mapping on existing parameters does not produce expected behaviour.

Steps to reproduce
  1. create a parameter on an instrument instance (here named: 'vna') (or have an existing one)
vna.add_parameter(
    name="sweep_type",
    get_cmd='SWPT?',
    set_cmd='SWPT {}',
    val_mapping={
        "Linear frequency": "LINF",
        "Power": "POWE"
    }
) 
  1. update val_mapping
vna.sweep_type.val_mapping = {'Linear frequency': 'LINF', 'Logarithmic frequency': 'LOGF'}
  1. set parameter to a: removed or b: added value or c: get value from instrument (instrument replying with: 'LOGF')
    a: vna.sweep_type('Power')
    b: vna.sweep_type('Logarithmic fequency')
    c: vna.sweep_type()
Expected behaviour

a: ValueError: ("'Power' is not in {'Logarithmic frequency', 'Linear frequency'}; ...)
b: parameter set to: 'Logarithmic frequency' without error
c: return 'Logarithmic frequency'

Actual behaviour

a: KeyError: ('Power', 'setting vna_sweep_type to Power')
b: ValueError: ("'Logarithmic fequency' is not in {'Power', 'Linear frequency'}; ...
c: KeyError: ("'LOGF' not in val_mapping", 'getting vna_sweep_type')

System

It would be helpful to provide such information:

Windows 10

If you are using a released version of qcodes (recommended):
0.34.1 (from ...\qcodes\_version.py)

Remarks

I'm trying to wirte an instrument driver and can change vals or unit without issue.
But maybe I am using the wrong approach, and Qcodes actully works as intended?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with an instrument parameter created through add_parameter and then change its val_mapping as shown. Trace the parameter's set and get behavior for removed, added, and instrument-returned values; done means all three cases produce the expected ValueError, mapped setting, and mapped return value.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.