Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

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

未关闭
#5,232 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
52/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
numpy, python
领域
data

调研方向

从复现示例中的 Measurement、datasaver.dataset 和 to_xarray_dataset 入口点开始,然后跟踪 ParamSpec 的 depends_on 元数据如何转换为 xarray 变量。使用确定性的 setpoints 复现该示例,并比较 X、Y 和独立 Z 的最终依赖关系。完成的标准是 Y 依赖于 X,而 Z 依赖于索引,并为此案例添加回归覆盖。

由索引模型根据 Issue 内容生成。

描述

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
主要语言
Python
星标
464
派生
364
平均合并
16 小时 20 分钟
30 天内合并 PR
100

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/Qcodes 的其他 Issue

查看 microsoft/Qcodes 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。