Repository: microsoft/Qcodes

Issue:
Wrong measurement results:
When doing my numerical simulations, I get the following result:

<img width="489" alt="capture" src="https://cloud.githubusercontent.com/assets/10207298/14728439/87bd5b9a-07e9-11e6-9d65-9b66251e6a52.PNG">

This looks more like an experimental result than a theoretical one (When I ran this simulation without the instrument server and dataserver, the result was fine)
The code I used to run the loop was
`loop = qc.Loop(simulation.gate[-0.3:0.3:0.01], 0.01).loop(simulation.ldos_omega[-0.8:0.8:0.01], 0.01).each(simulation.ldos)
data = loop.run()`

It worries me a lot that qcodes does not accurately reflects the data produced by the measurement/simulation,
looking at the datafile itself, It can be seen that the same values are put in the output over and over again.

This behavior is reproducible and is sometimes combined with the following  but note however that an error is not always generated and it is possible to only get a result like the plot I showed above without error:

```

---------------------------------------------------------------------------
Empty                                     Traceback (most recent call last)
c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\widgets\widgets.py in do_update(self, content, buffers)
     44 
     45     def do_update(self, content=None, buffers=None):
---> 46         self._message = str(self._fn())
     47 
     48     def halt(self):

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\plots\base.py in update(self)
    161         any_updates = False
    162         for updater in self.data_updaters:
--> 163             updates = updater()
    164             if updates is not False:
    165                 any_updates = True

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\data\data_set.py in sync(self)
    312 
    313         with self.data_manager.query_lock:
--> 314             if self.is_on_server:
    315                 # TODO: can we reduce the amount of data to send?
    316                 # seems like in the most general case this would need to

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\data\data_set.py in is_on_server(self)
    286 
    287         with self.data_manager.query_lock:
--> 288             live_location = self.data_manager.ask('get_data', 'location')
    289             return self.location == live_location
    290 

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\utils\multiprocessing.py in ask(self, timeout, *query)
    332                 if self._error_queue.empty():
    333                     # only raise if we're not about to find a deeper error
--> 334                     raise e
    335             self._check_for_errors(self._expect_error)
    336 

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\utils\multiprocessing.py in ask(self, timeout, *query)
    324 
    325             try:
--> 326                 res = self._check_response(timeout)
    327 
    328                 while not self._response_queue.empty():

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\utils\multiprocessing.py in _check_response(self, timeout)
    301 
    302     def _check_response(self, timeout):
--> 303         res = self._response_queue.get(timeout=timeout)
    304         if res == SERVER_ERR:
    305             self._expect_error = True

C:\Users\t-dadejo\AppData\Local\Continuum\Anaconda3\envs\santabarbara\lib\multiprocessing\queues.py in get(self, block, timeout)
    103                     timeout = deadline - time.time()
    104                     if timeout < 0 or not self._poll(timeout):
--> 105                         raise Empty
    106                 elif not self._poll():
    107                     raise Empty

Empty: 





---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\widgets\widgets.py in do_update(self, content, buffers)
     44 
     45     def do_update(self, content=None, buffers=None):
---> 46         self._message = str(self._fn())
     47 
     48     def halt(self):

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\plots\base.py in update(self)
    161         any_updates = False
    162         for updater in self.data_updaters:
--> 163             updates = updater()
    164             if updates is not False:
    165                 any_updates = True

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\data\data_set.py in sync(self)
    318                 # changed since that particular client last synced
    319                 # (at least first and last pt)
--> 320                 live_data = self.data_manager.ask('get_data').arrays
    321                 for array_id in self.arrays:
    322                     self.arrays[array_id].ndarray = live_data[array_id].ndarray

AttributeError: 'str' object has no attribute 'arrays'





---------------------------------------------------------------------------
Empty                                     Traceback (most recent call last)
c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\widgets\widgets.py in do_update(self, content, buffers)
     44 
     45     def do_update(self, content=None, buffers=None):
---> 46         self._message = str(self._fn())
     47 
     48     def halt(self):

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\plots\base.py in update(self)
    161         any_updates = False
    162         for updater in self.data_updaters:
--> 163             updates = updater()
    164             if updates is not False:
    165                 any_updates = True

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\data\data_set.py in sync(self)
    312 
    313         with self.data_manager.query_lock:
--> 314             if self.is_on_server:
    315                 # TODO: can we reduce the amount of data to send?
    316                 # seems like in the most general case this would need to

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\data\data_set.py in is_on_server(self)
    286 
    287         with self.data_manager.query_lock:
--> 288             live_location = self.data_manager.ask('get_data', 'location')
    289             return self.location == live_location
    290 

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\utils\multiprocessing.py in ask(self, timeout, *query)
    332                 if self._error_queue.empty():
    333                     # only raise if we're not about to find a deeper error
--> 334                     raise e
    335             self._check_for_errors(self._expect_error)
    336 

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\utils\multiprocessing.py in ask(self, timeout, *query)
    324 
    325             try:
--> 326                 res = self._check_response(timeout)
    327 
    328                 while not self._response_queue.empty():

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\utils\multiprocessing.py in _check_response(self, timeout)
    301 
    302     def _check_response(self, timeout):
--> 303         res = self._response_queue.get(timeout=timeout)
    304         if res == SERVER_ERR:
    305             self._expect_error = True

C:\Users\t-dadejo\AppData\Local\Continuum\Anaconda3\envs\santabarbara\lib\multiprocessing\queues.py in get(self, block, timeout)
    103                     timeout = deadline - time.time()
    104                     if timeout < 0 or not self._poll(timeout):
--> 105                         raise Empty
    106                 elif not self._poll():
    107                     raise Empty

Empty: 





---------------------------------------------------------------------------
Empty                                     Traceback (most recent call last)
c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\widgets\widgets.py in do_update(self, content, buffers)
     44 
     45     def do_update(self, content=None, buffers=None):
---> 46         self._message = str(self._fn())
     47 
     48     def halt(self):

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\plots\base.py in update(self)
    161         any_updates = False
    162         for updater in self.data_updaters:
--> 163             updates = updater()
    164             if updates is not False:
    165                 any_updates = True

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\data\data_set.py in sync(self)
    312 
    313         with self.data_manager.query_lock:
--> 314             if self.is_on_server:
    315                 # TODO: can we reduce the amount of data to send?
    316                 # seems like in the most general case this would need to

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\data\data_set.py in is_on_server(self)
    286 
    287         with self.data_manager.query_lock:
--> 288             live_location = self.data_manager.ask('get_data', 'location')
    289             return self.location == live_location
    290 

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\utils\multiprocessing.py in ask(self, timeout, *query)
    332                 if self._error_queue.empty():
    333                     # only raise if we're not about to find a deeper error
--> 334                     raise e
    335             self._check_for_errors(self._expect_error)
    336 

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\utils\multiprocessing.py in ask(self, timeout, *query)
    324 
    325             try:
--> 326                 res = self._check_response(timeout)
    327 
    328                 while not self._response_queue.empty():

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\utils\multiprocessing.py in _check_response(self, timeout)
    301 
    302     def _check_response(self, timeout):
--> 303         res = self._response_queue.get(timeout=timeout)
    304         if res == SERVER_ERR:
    305             self._expect_error = True

C:\Users\t-dadejo\AppData\Local\Continuum\Anaconda3\envs\santabarbara\lib\multiprocessing\queues.py in get(self, block, timeout)
    103                     timeout = deadline - time.time()
    104                     if timeout < 0 or not self._poll(timeout):
--> 105                         raise Empty
    106                 elif not self._poll():
    107                     raise Empty

Empty: 





---------------------------------------------------------------------------
Empty                                     Traceback (most recent call last)
c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\widgets\widgets.py in do_update(self, content, buffers)
     44 
     45     def do_update(self, content=None, buffers=None):
---> 46         self._message = str(self._fn())
     47 
     48     def halt(self):

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\plots\base.py in update(self)
    161         any_updates = False
    162         for updater in self.data_updaters:
--> 163             updates = updater()
    164             if updates is not False:
    165                 any_updates = True

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\data\data_set.py in sync(self)
    312 
    313         with self.data_manager.query_lock:
--> 314             if self.is_on_server:
    315                 # TODO: can we reduce the amount of data to send?
    316                 # seems like in the most general case this would need to

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\data\data_set.py in is_on_server(self)
    286 
    287         with self.data_manager.query_lock:
--> 288             live_location = self.data_manager.ask('get_data', 'location')
    289             return self.location == live_location
    290 

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\utils\multiprocessing.py in ask(self, timeout, *query)
    332                 if self._error_queue.empty():
    333                     # only raise if we're not about to find a deeper error
--> 334                     raise e
    335             self._check_for_errors(self._expect_error)
    336 

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\utils\multiprocessing.py in ask(self, timeout, *query)
    324 
    325             try:
--> 326                 res = self._check_response(timeout)
    327 
    328                 while not self._response_queue.empty():

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\utils\multiprocessing.py in _check_response(self, timeout)
    301 
    302     def _check_response(self, timeout):
--> 303         res = self._response_queue.get(timeout=timeout)
    304         if res == SERVER_ERR:
    305             self._expect_error = True

C:\Users\t-dadejo\AppData\Local\Continuum\Anaconda3\envs\santabarbara\lib\multiprocessing\queues.py in get(self, block, timeout)
    103                     timeout = deadline - time.time()
    104                     if timeout < 0 or not self._poll(timeout):
--> 105                         raise Empty
    106                 elif not self._poll():
    107                     raise Empty

Empty: 





---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\widgets\widgets.py in do_update(self, content, buffers)
     44 
     45     def do_update(self, content=None, buffers=None):
---> 46         self._message = str(self._fn())
     47 
     48     def halt(self):

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\plots\base.py in update(self)
    161         any_updates = False
    162         for updater in self.data_updaters:
--> 163             updates = updater()
    164             if updates is not False:
    165                 any_updates = True

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\data\data_set.py in sync(self)
    318                 # changed since that particular client last synced
    319                 # (at least first and last pt)
--> 320                 live_data = self.data_manager.ask('get_data').arrays
    321                 for array_id in self.arrays:
    322                     self.arrays[array_id].ndarray = live_data[array_id].ndarray

AttributeError: 'str' object has no attribute 'arrays'





---------------------------------------------------------------------------
Empty                                     Traceback (most recent call last)
c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\widgets\widgets.py in do_update(self, content, buffers)
     44 
     45     def do_update(self, content=None, buffers=None):
---> 46         self._message = str(self._fn())
     47 
     48     def halt(self):

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\plots\base.py in update(self)
    161         any_updates = False
    162         for updater in self.data_updaters:
--> 163             updates = updater()
    164             if updates is not False:
    165                 any_updates = True

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\data\data_set.py in sync(self)
    322                     self.arrays[array_id].ndarray = live_data[array_id].ndarray
    323 
--> 324                 measuring = self.data_manager.ask('get_measuring')
    325                 if not measuring:
    326                     # we must have *just* stopped measuring

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\utils\multiprocessing.py in ask(self, timeout, *query)
    332                 if self._error_queue.empty():
    333                     # only raise if we're not about to find a deeper error
--> 334                     raise e
    335             self._check_for_errors(self._expect_error)
    336 

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\utils\multiprocessing.py in ask(self, timeout, *query)
    324 
    325             try:
--> 326                 res = self._check_response(timeout)
    327 
    328                 while not self._response_queue.empty():

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\utils\multiprocessing.py in _check_response(self, timeout)
    301 
    302     def _check_response(self, timeout):
--> 303         res = self._response_queue.get(timeout=timeout)
    304         if res == SERVER_ERR:
    305             self._expect_error = True

C:\Users\t-dadejo\AppData\Local\Continuum\Anaconda3\envs\santabarbara\lib\multiprocessing\queues.py in get(self, block, timeout)
    103                     timeout = deadline - time.time()
    104                     if timeout < 0 or not self._poll(timeout):
--> 105                         raise Empty
    106                 elif not self._poll():
    107                     raise Empty

Empty: 





---------------------------------------------------------------------------
Empty                                     Traceback (most recent call last)
c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\widgets\widgets.py in do_update(self, content, buffers)
     44 
     45     def do_update(self, content=None, buffers=None):
---> 46         self._message = str(self._fn())
     47 
     48     def halt(self):

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\plots\base.py in update(self)
    161         any_updates = False
    162         for updater in self.data_updaters:
--> 163             updates = updater()
    164             if updates is not False:
    165                 any_updates = True

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\data\data_set.py in sync(self)
    312 
    313         with self.data_manager.query_lock:
--> 314             if self.is_on_server:
    315                 # TODO: can we reduce the amount of data to send?
    316                 # seems like in the most general case this would need to

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\data\data_set.py in is_on_server(self)
    286 
    287         with self.data_manager.query_lock:
--> 288             live_location = self.data_manager.ask('get_data', 'location')
    289             return self.location == live_location
    290 

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\utils\multiprocessing.py in ask(self, timeout, *query)
    332                 if self._error_queue.empty():
    333                     # only raise if we're not about to find a deeper error
--> 334                     raise e
    335             self._check_for_errors(self._expect_error)
    336 

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\utils\multiprocessing.py in ask(self, timeout, *query)
    324 
    325             try:
--> 326                 res = self._check_response(timeout)
    327 
    328                 while not self._response_queue.empty():

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\utils\multiprocessing.py in _check_response(self, timeout)
    301 
    302     def _check_response(self, timeout):
--> 303         res = self._response_queue.get(timeout=timeout)
    304         if res == SERVER_ERR:
    305             self._expect_error = True

C:\Users\t-dadejo\AppData\Local\Continuum\Anaconda3\envs\santabarbara\lib\multiprocessing\queues.py in get(self, block, timeout)
    103                     timeout = deadline - time.time()
    104                     if timeout < 0 or not self._poll(timeout):
--> 105                         raise Empty
    106                 elif not self._poll():
    107                     raise Empty

Empty: 





---------------------------------------------------------------------------
Empty                                     Traceback (most recent call last)
c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\widgets\widgets.py in do_update(self, content, buffers)
     44 
     45     def do_update(self, content=None, buffers=None):
---> 46         self._message = str(self._fn())
     47 
     48     def halt(self):

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\plots\base.py in update(self)
    161         any_updates = False
    162         for updater in self.data_updaters:
--> 163             updates = updater()
    164             if updates is not False:
    165                 any_updates = True

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\data\data_set.py in sync(self)
    312 
    313         with self.data_manager.query_lock:
--> 314             if self.is_on_server:
    315                 # TODO: can we reduce the amount of data to send?
    316                 # seems like in the most general case this would need to

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\data\data_set.py in is_on_server(self)
    286 
    287         with self.data_manager.query_lock:
--> 288             live_location = self.data_manager.ask('get_data', 'location')
    289             return self.location == live_location
    290 

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\utils\multiprocessing.py in ask(self, timeout, *query)
    332                 if self._error_queue.empty():
    333                     # only raise if we're not about to find a deeper error
--> 334                     raise e
    335             self._check_for_errors(self._expect_error)
    336 

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\utils\multiprocessing.py in ask(self, timeout, *query)
    324 
    325             try:
--> 326                 res = self._check_response(timeout)
    327 
    328                 while not self._response_queue.empty():

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\utils\multiprocessing.py in _check_response(self, timeout)
    301 
    302     def _check_response(self, timeout):
--> 303         res = self._response_queue.get(timeout=timeout)
    304         if res == SERVER_ERR:
    305             self._expect_error = True

C:\Users\t-dadejo\AppData\Local\Continuum\Anaconda3\envs\santabarbara\lib\multiprocessing\queues.py in get(self, block, timeout)
    103                     timeout = deadline - time.time()
    104                     if timeout < 0 or not self._poll(timeout):
--> 105                         raise Empty
    106                 elif not self._poll():
    107                     raise Empty

Empty: 





---------------------------------------------------------------------------
Empty                                     Traceback (most recent call last)
c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\widgets\widgets.py in do_update(self, content, buffers)
     44 
     45     def do_update(self, content=None, buffers=None):
---> 46         self._message = str(self._fn())
     47 
     48     def halt(self):

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\plots\base.py in update(self)
    161         any_updates = False
    162         for updater in self.data_updaters:
--> 163             updates = updater()
    164             if updates is not False:
    165                 any_updates = True

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\data\data_set.py in sync(self)
    312 
    313         with self.data_manager.query_lock:
--> 314             if self.is_on_server:
    315                 # TODO: can we reduce the amount of data to send?
    316                 # seems like in the most general case this would need to

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\data\data_set.py in is_on_server(self)
    286 
    287         with self.data_manager.query_lock:
--> 288             live_location = self.data_manager.ask('get_data', 'location')
    289             return self.location == live_location
    290 

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\utils\multiprocessing.py in ask(self, timeout, *query)
    332                 if self._error_queue.empty():
    333                     # only raise if we're not about to find a deeper error
--> 334                     raise e
    335             self._check_for_errors(self._expect_error)
    336 

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\utils\multiprocessing.py in ask(self, timeout, *query)
    324 
    325             try:
--> 326                 res = self._check_response(timeout)
    327 
    328                 while not self._response_queue.empty():

c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\utils\multiprocessing.py in _check_response(self, timeout)
    301 
    302     def _check_response(self, timeout):
--> 303         res = self._response_queue.get(timeout=timeout)
    304         if res == SERVER_ERR:
    305             self._expect_error = True

C:\Users\t-dadejo\AppData\Local\Continuum\Anaconda3\envs\santabarbara\lib\multiprocessing\queues.py in get(self, block, timeout)
    103                     timeout = deadline - time.time()
    104                     if timeout < 0 or not self._poll(timeout):
--> 105                         raise Empty
    106                 elif not self._poll():
    107                     raise Empty

Empty: 





Traceback (most recent call last):
  File "c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\data\format.py", line 94, in read
    self.read_one_file(data_set, f, ids_read)
  File "c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\data\format.py", line 343, in read_one_file
    myindices, indices)
ValueError: ('inconsistent setpoint values', -0.28000000000000003, -0.0, 'gate', (2,), [2, 76])

error reading file 2016-04-21\17-44-28.dat
Traceback (most recent call last):
  File "c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\data\format.py", line 94, in read
    self.read_one_file(data_set, f, ids_read)
  File "c:\users\t-dadejo\pycharm_projects\qcodes\qcodes\data\format.py", line 343, in read_one_file
    myindices, indices)
ValueError: ('inconsistent setpoint values', 0.20000000000000001, 0.0, 'gate', (50,), [50, 49])
```



Discussion:
To clarify more on this issue and hoping for a fast resolution of this issue I will post some about this. I am worrying that in experimental setups you might not resolve this behavior because it might be attributed to experimental noise/weirdness. Maybe more of you guys are experiencing this without even knowing it.

**The good**
When I run the simulation with:

``` python
loop = qc.Loop(simulation.gate[-0.3:0.3:0.01], 0.0).loop(simulation.ldos_omega[-0.8:0.8:0.01], 0.0).each(simulation.ldos)
data = loop.run(background=False, data_manager=False, location='testsweep', overwrite=True)
```

I can plot the data afterwards and get the result:
![image](https://cloud.githubusercontent.com/assets/10207298/14791037/e2e327f2-0ac8-11e6-8891-699273aa36b8.png)
which looks like it should look like,

**The bad**
when I run the code however with

``` python
loop = qc.Loop(simulation.gate[-0.3:0.3:0.01], 0.0).loop(simulation.ldos_omega[-0.8:0.8:0.01], 0.0).each(simulation.ldos)
data = loop.run()
```

I get the result that I posted above. (repeated here)
![image](https://cloud.githubusercontent.com/assets/10207298/14791393/8cb115a4-0aca-11e6-9794-4bbf2f5e5b48.png)

Always the distorted figure, sometimes the error as well.
The distortion is not deterministic however, it will always look a little different.

I would like to ask the people now using "loops", can you check your data to see if you also get behavior like this (a small strip of values that are exactly the same)?
And @alexcjohnson , can you tell me what you would like from me to resolve this issue as fast and efficiently as possible?

EDIT: added figure from previous post

@damazter this looks really bad, and it concerns me. 

We have noted in differend places here that for instance the `background=False` does funny things.
If you only remove that one, how does your simulation look then?

@MerlinSmiles 
curiously enough, the `background=False` is the case that everything works as expected. When I remove this option, my liveplotting doesn't work because there is no dataserver working in this case.
The result is also not written to the file, so I am afraid that it is not possible for me to test this in any way.
(I would have to file two issues for this as well, but I think this issue has to be resolved first)

Ahh, i see, i hear alex is working on it...

@damazter yikes! I did see something like this - intermittently getting some repeated data, though in that case never more than one erroneous point at a time - quite a while ago in the example notebook and never figured out what it was. I hadn't seen it for some time so I thought I must have fixed it inadvertently. Fat chance!

Any chance you have some self-contained code I could use to reproduce this?

Just to be clear on what you're seeing: it appears that the measurements sometimes get associated with _later_ setpoints than they should. I'm guessing this has to do with commands getting put into queues out of order, perhaps because `ask` (get) commands (to any of our server processes) wait for a response but `write` (set) commands do not. I've been running through a bunch of hypotheses about how this could happen and may have some thoughts on how a single point could get repeated, but an explanation for a long string like this still eludes me...

I am afraid that I don't have a real self contained code.
I am suspecting that my simulation is slower than qcodes wants it to be. It feels like the loop skips a few beats. Hence a string of values don't get simulated but only the last one of them is and this value is then used for the entire (preceding) string.

I will try to give you access to my development repo for this code, then it would be possible to just run the code. But a real self-contained example would be better, I think So let me give that a try first.

Now I come to think of it: if write commands do not wait for a response, is it possible in any way that qcodes continues with setting values while the simulation is running? So while the `ask` is going on, the next writes are already executed?
Would it be possible to remove the `write` command and replace them by `asks` (which seems to be more controlled I think)(maybe This could be tested in a separate branch, then I can test that branch with my code, @alexcjohnson what do you think?)

> Now I come to think of it: if write commands do not wait for a response, is it possible in any way that qcodes continues with setting values while the simulation is running? So while the `ask` is going on, the next writes are already executed?

That's certainly what it looks like, I just don't see how that could be happening.

> Would it be possible to remove the `write` command and replace them by `asks` (which seems to be more controlled I think)(maybe This could be tested in a separate branch, then I can test that branch with my code, @alexcjohnson what do you think)

Yes, I'm thinking this would be a good idea anyway - for instance if a `set` has a built-in ramp or other delay, we want to wait for it to finish before we attempt to acquire data at the new setpoint. There's really only one place where I _really_ want write to not wait for a response from the server, and that's when pushing data to the `DataServer`, so when it decides to write to disk or something it doesn't stop more data from coming in. I'll give it a shot.

I got a self contained example:
instrument driver:

``` python
import qcodes as qc
from qcodes.instrument.parameter import ManualParameter


class Dummy(qc.Instrument):

    def __init__(self, name, **kwargs):
        super().__init__(name, **kwargs)
        self.add_parameter("ldos_omega", parameter_class=ManualParameter, initial_value=0)
        self.add_parameter("ldos_i", parameter_class=ManualParameter, initial_value=1)

        self.add_parameter("ldos", get_cmd=self.get_ldos)

    def get_ldos(self):
        return self.ldos_omega.get()
```

notebook code:

``` python

# coding: utf-8

# In[1]:

get_ipython().magic('matplotlib nbagg')
from matplotlib import pyplot
import time
import numpy as np
import qcodes as qc
qc.set_mp_method('spawn')
qc.show_subprocess_widget()

import wines.dummy


# In[2]:

dm = qc.data.manager.get_data_manager()


# In[3]:

try:
    simulation = wines.dummy.Dummy('Dummy', server_name='dummy')
except:
    simulation = wines.dummy.Dummy('Dummy', server_name='dummy')


# In[4]:

loop = qc.Loop(simulation.ldos_i[-0.3:0.3:0.01], 0.0).loop(simulation.ldos_omega[-0.8:0.8:0.01], 0.0).each(simulation.ldos)
data = loop.run()


# In[5]:

qc.MatPlot(data.ldos)

```

using "restart kernel and run all" gives me:
![dummy](https://cloud.githubusercontent.com/assets/10207298/14798693/b9517770-0aed-11e6-8012-da7ad326b3c4.png)

wow, ok - looks fine on mac, but I see the problem on PC. Investigating...


Resolving patch:
diff --git a/qcodes/loops.py b/qcodes/loops.py
--- a/qcodes/loops.py
+++ b/qcodes/loops.py
@@ -613,9 +613,7 @@ def __init__(self, params_indices, data_set, use_threads):
         self.store = data_set.store
 
         # for performance, pre-calculate which params return data for
-        # multiple arrays, pre-create the dict to pass these to store fn
-        # and pre-calculate the name mappings
-        self.dict = {}
+        # multiple arrays, and the name mappings
         self.getters = []
         self.param_ids = []
         self.composite = []
@@ -627,16 +625,15 @@ def __init__(self, params_indices, data_set, use_threads):
                 for i in range(len(param.names)):
                     param_id = data_set.action_id_map[action_indices + (i,)]
                     part_ids.append(param_id)
-                    self.dict[param_id] = None
                 self.param_ids.append(None)
                 self.composite.append(part_ids)
             else:
                 param_id = data_set.action_id_map[action_indices]
-                self.dict[param_id] = None
                 self.param_ids.append(param_id)
                 self.composite.append(False)
 
     def __call__(self, loop_indices, **ignore_kwargs):
+        out_dict = {}
         if self.use_threads:
             out = thread_map(self.getters)
         else:
@@ -646,11 +643,11 @@ def __call__(self, loop_indices, **ignore_kwargs):
                                                   self.composite):
             if composite:
                 for val, part_id in zip(param_out, composite):
-                    self.dict[part_id] = val
+                    out_dict[part_id] = val
             else:
-                self.dict[param_id] = param_out
+                out_dict[param_id] = param_out
 
-        self.store(loop_indices, self.dict)
+        self.store(loop_indices, out_dict)
 
 
 class _Nest:


Test patch: