microsoft / microsoft/Qcodes

Writing Sweep in a more dynamic way is not working

Open
#3,474 4 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

Hello,
I am trying to write the following function in a more dynamic way:

```
with Measurement(get_measurement_name) as msmt:

for i in Sweep(sweep_elements[0][0],sweep_elements[0][1], sweep_elements[0][2]): # dim = 18
for i in Sweep(sweep_elements[1][0],sweep_elements[1][1]): # dim = 5
msmt.measure(prog(n_points),name = 'dumm',label=label_name)

```
Here, instead of writing many sweep and many for loop, I am giving the sweep elements into an array like that:
`sweep_elements = [[time,'time','s'],[range(5),'repititons']]`
And I am writing the following code
```
with Measurement(get_measurement_name) as msmt:

iterables = (Sweep(*inner) for inner in sweep_elements)
for values in itertools.product(*iterables):
msmt.measure(prog(n_points),name = 'dumm',label=label_name)
```
However it is not working and I am getting this error :
measurement.py in _add_measurement_result(self, action_indices, result, parameter, store, name, label, unit)
557 ndim = len(self.loop_indices)
558 if len(data_array.set_arrays) != ndim + result.ndim:
--> 559 raise RuntimeError(
560 f"Wrong number of set arrays for {data_array.name}. "
561 f"Expected {ndim + result.ndim} instead of "

RuntimeError: Wrong number of set arrays for result. Expected 2 instead of 3.
I have no idea what I did wrong. It seems to me all correct
Could you please help me and tell me what is going on here

Thanks,
Best

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

Start in measurement.py at _add_measurement_result and reproduce the reported RuntimeError using the dynamic Sweep and itertools.product example from the issue. Trace loop_indices and set_arrays for the generated measurement, then verify that the dynamic form produces the same dimensional result as the explicit nested loops.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.