Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xarray dataset dependency is incorrect when adding an independent parameter to the measurement #5232

Open
einsmein opened this issue Jun 21, 2023 · 0 comments

Comments

@einsmein
Copy link

I created a parameter with setpoints Y which depends on setpoint X.
Then I created another parameter Z which is independent from the other two.
I measured Y and Z in the measurement context, then convert the result dataset to an xarray.

Expected behaviour

I expect that the Y would be a data variable that depends on X, and Z on index, as inferred from the paramspecs.

{'foo_instrument_X': ParamSpec('foo_instrument_X', 'array', 'X', '', inferred_from=[], depends_on=[]),
 'foo_instrument_Y': ParamSpec('foo_instrument_Y', 'array', 'Y', '', inferred_from=[], depends_on=['foo_instrument_X']),
 'foo_instrument_Z': ParamSpec('foo_instrument_Z', 'numeric', 'Z', '', inferred_from=[], depends_on=[])}

Actual behaviour

All parameters became data variables that depended on index.
image

Steps to reproduce

Run the following snippet

import numpy as np
import qcodes as qc
from qcodes import Measurement
from qcodes.instrument import Instrument
from qcodes.parameters import Parameter, ParameterWithSetpoints
from qcodes.validators import Arrays, Numbers
class FooGeneratedSetpoints(Parameter):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
    def get_raw(self):
        return np.array(range(4,8))
class FooArray(ParameterWithSetpoints):
    def get_raw(self):
        return np.array(range(4))
class FooInstrument(Instrument):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.add_parameter(
            "X",
            parameter_class=FooGeneratedSetpoints,
            vals=Arrays(shape=(4,))
        )
        self.add_parameter(
            "Y",
            parameter_class=FooArray,
            setpoints=(self.X,),
            vals=Arrays(shape=(4,))
        )
foo = FooInstrument("foo_instrument")

foo.add_parameter("Z", set_cmd=None)

meas = Measurement()
meas.register_parameter(foo.Y)
meas.register_parameter(foo.Z)
with meas.run() as datasaver:
    for z in range(8,12):
        datasaver.add_result(
            (foo.Y, foo.Y()), (foo.Z, z)
        )
    dataset = datasaver.dataset
dataset.to_xarray_dataset()

If I modify the setpoint to the following, the issue disappeared and the result dataset is as expected.

from random import random
class FooGeneratedSetpoints(Parameter):
    ...
    def get_raw(self):
        return np.array([random() + i for i in range(4,8)])
...
image
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

No branches or pull requests

1 participant