microsoft / Qcodes

Modular data acquisition framework
http://microsoft.github.io/Qcodes/
MIT License
337 stars 315 forks source link

Writing Sweep in a more dynamic way is not working #3474

Open apassenger opened 3 years ago

apassenger commented 3 years ago

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

jenshnielsen commented 3 years ago

@apassenger Thanks for your question.

The error says that it expects your data to be 2 dimensional but it is actually 3 dimensional. Without being able to see what sweep_elements is it is a bit hard to figure out what exactly is going on. Could I ask you to write your examples in such a way that I can execute them directly if possible?

apassenger commented 3 years ago

Hello, thanks for the answer My sweep_elements are here:

In the first code, the sweep_elements corresponds this code lines:

`with Measurement('getting_current') as msmt:
    for i in Sweep(time,'time', unit = 's'): # dim = 18
        for i in Sweep(range(5),'repetitions'): # dim = 5
             msmt.measure(measure_current(5),name = 'dumm', label = 'holq')`

In the second code, the elements are in the list:

sweep_elements = [[time,'time','s'],[range(5),'repititons']] And time is defined:time=np.arange(.1,1,step=.1) n_points is an integer value the prog is written in qua language. if you want I can put this code too

apassenger commented 3 years ago

Hello Do you have any update?

jenshnielsen commented 3 years ago

Hi again. Please provide a Short, Self Contained, Correct (Compilable), Example http://www.sscce.org/ such that I can copy paste the code from your example to a python prompt and then execute it to see the issue. Otherwise I will have to manually piece together the pieces that you have provided and I unfortunately do not have. Also if possible please write the example such that it does not depend on qua