microsoft / microsoft/Qcodes

BUG: data gets saved to database twice

Open
#1,221 2 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

### Steps to reproduce

I ran a 2D scan using the do2d function in my pull request, which is basically a copy/paste of the do2d function provided in the qcodes examples for the new dataset.

`do2d(qdac.lp, -0.75, -0.9, 500, 0.07, qdac.b, -0.5, 0.5, 100, 0.07, lockin_2.X, lockin_2.Y)`

For completeness I provide the function here:

```python
def do2d(param_set1, start1, stop1, num_points1, delay1,
param_set2, start2, stop2, num_points2, delay2,
*param_meas):
'''Scan 2D of param_set and measure param_meas.'''
meas = Measurement()
refresh_time = 1. # in s
meas.write_period = refresh_time
meas.register_parameter(param_set1)
param_set1.post_delay = delay1
meas.register_parameter(param_set2)
param_set2.post_delay = delay2
output = []
for parameter in param_meas:
meas.register_parameter(parameter, setpoints=(param_set1, param_set2))
output.append([parameter, None])
progress_bar = progressbar.ProgressBar(max_value=num_points1 * num_points2)
points_taken = 0
time.sleep(0.1)

with meas.run() as datasaver:
run_id = datasaver.run_id
last_time = time.time()
for set_point1 in np.linspace(start1, stop1, num_points1):
param_set1.set(set_point1)
for set_point2 in np.linspace(start2, stop2, num_points2):
param_set2.set(set_point2)
for i, parameter in enumerate(param_meas):
output[i][1] = parameter.get()
datasaver.add_result((param_set1, set_point1),
(param_set2, set_point2),
*output)
points_taken += 1
current_time = time.time()
if current_time - last_time >= refresh_time:
last_time = current_time
progress_bar.update(points_taken)
progress_bar.update(points_taken)
return run_id
```

### Expected behavior

Each point should get saved once.

### Actual behaviour

Some points get saved more than once (which destroys alignment of the data if your data analysis relies on it). Excerpt from the table:

...
-7,50E+17 | -2,27E+17 | 2,89E+15 | -1,14E+15
-7,50E+17 | -2,17E+17 | 2,88E+15 | -1,18E+15
-7,50E+17 | -2,07E+17 | 2,79E+15 | -1,23E+15
-7,50E+17 | -1,97E+17 | 2,74E+15 | -1,23E+15
-7,50E+17 | -1,87E+17 | 2,74E+15 | -1,19E+15
-7,50E+17 | -1,77E+17 | 2,76E+15 | -1,16E+15
-7,50E+17 | -1,67E+17 | 2,81E+15 | -1,17E+15
-7,50E+17 | -1,57E+17 | 2,86E+15 | -1,24E+15
-7,50E+17 | -1,46E+17 | 2,82E+15 | -1,30E+15
-7,50E+17 | -1,36E+17 | 2,66E+15 | -1,25E+15
-7,50E+17 | -1,26E+17 | 2,43E+15 | -1,15E+15
-7,50E+17 | -1,16E+17 | 2,29E+15 | -1,10E+15
-7,50E+17 | -2,27E+17 | 2,89E+15 | -1,14E+15
-7,50E+17 | -2,17E+17 | 2,88E+15 | -1,18E+15
-7,50E+17 | -2,07E+17 | 2,79E+15 | -1,23E+15
-7,50E+17 | -1,97E+17 | 2,74E+15 | -1,23E+15
...

In this case there is a 12 row block that gets repeated.

### System

Windows 10

**qcodes branch master**

**qcodes commit f85dfeebd02e7c9cacf925195bbd2217a45d9df7**

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 with the shown do2d entry point, especially Measurement.run() and datasaver.add_result(), and reproduce the repeated 12-row block using the supplied scan parameters. Trace how results are persisted and identify why rows are written more than once. Done means each scan point appears exactly once and the resulting data remains aligned.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.