Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matplotlib can't handle more than 499 data points #380

Closed
giulioungaretti opened this issue Nov 4, 2016 · 12 comments · Fixed by #421
Closed

Matplotlib can't handle more than 499 data points #380

giulioungaretti opened this issue Nov 4, 2016 · 12 comments · Fixed by #421
Labels

Comments

@giulioungaretti
Copy link
Contributor

giulioungaretti commented Nov 4, 2016

Bug from Thorvald at qdev.

Steps to reproduce

# VNA power scan:
v1.spec_mode(0)
v1.bandwidth(500)
v1.avg(5)

a = 6.61064e9;
v1.start(a-20e6)
v1.stop(a+20e6)
v1.npts(101)

loop = qc.Loop(v1.power.sweep(-45,-55,1)).each(v1.trace)
data = loop.get_data_set();
plot=qc.MatPlot(array, subplots=(1,2))
plot.add(array, subplot=2)
loop.with_bg_task(plot.update, 0.0005).run()

Expected behaviour

The plot should show the data

Actual behaviour

The plot only show the data if a row has less than 499 points

System

windows

qcodes branch
master

qcodes commit
3475e49

@nataliejpg
Copy link
Contributor

nb (from Thorvald) this was after a MatPlot update 1.5.3 although hadn't tried with this many points before the update). On downgrading to 1.5.1 still broken...

@jenshnielsen jenshnielsen changed the title Matplotli can't handle more than 499 data points Matplotlib can't handle more than 499 data points Dec 2, 2016
@jenshnielsen
Copy link
Collaborator

Is this specific to one instrument.

I can't reproduce it doing something simple with a mock instrument (Slightly modified from the base tutorial producing a 600 time 650 plot in the end.

%matplotlib nbagg
import matplotlib.pyplot as plt
from pprint import pprint
import time
import numpy as np
import qcodes as qc

# spawn doesn't like function or class definitions in the interpreter
# session - had to move them to a file.
from toymodel import AModel, MockGates, MockSource, MockMeter, AverageGetter, AverageAndRaw

# now create this "experiment", note that all these are instruments 
model = AModel()
gates = MockGates('gates', model=model)
source = MockSource('source', model=model)
meter = MockMeter('meter', model=model)

# The station is a container for all instruments that makes it easy 
# to log meta-data
station = qc.Station(gates, source, meter)

# it's nice to have the key parameters be part of the global namespace
# that way they're objects that we can easily set, get, and slice
c0, c1, c2, vsd = gates.chan0, gates.chan1, gates.chan2, source.amplitude

loop = qc.Loop(c1[-30:30:0.1], 0.01).loop(c0[-30:35:.1], 0.00001).each(
    meter.amplitude, # first measurement, at c2=0 -> amplitude_0 bcs it's action 0
    qc.Task(c2.set, 1), # action 1 -> c2.set(1)
    meter.amplitude, # second measurement, at c2=1 -> amplitude_2 bcs it's action 2
    qc.Task(c2.set, 0)
    )
data = loop.get_data_set(name='2D_test')

plot = qc.MatPlot(data.meter_amplitude_0, cmap=plt.cm.hot, figsize=(12, 4.5), subplots=(1, 2))
plot.add(data.meter_amplitude_2, cmap=plt.cm.hot, subplot=2)
data2 = loop.with_bg_task(plot.update, plot.save,  0.0000001).run()

@nataliejpg
Copy link
Contributor

nope, we get it with alazar and VNA measurements on two different computers (I don't have great confidence in the version control on either computer but they used different install methods so that's at least 2 data points :P). Both live plot and plotting old data. Didn't try it out with the tutorial notebook but I can try running the above code when I have a moment and see how it looks.

@jenshnielsen
Copy link
Collaborator

That would be great. I am happy to test out the instrument too just need to hook it up or use the lab computer

@nataliejpg
Copy link
Contributor

I think you'll have trouble getting hold of either of those instruments to be honest :P I guess it could be something to do with the 'hard parameter' aspect of it but that seems a bit obscure. PyQt plot has previously had a 'nonlinearity of setpoints' issue but its not obvious to me that it's linked. I'll let you know when I've tested the tutorial. It will late afternoon/tomorrow morning

@jenshnielsen
Copy link
Collaborator

Investigating this a bit more the issue seems to be that the frequency setpoint array being filed with NaNs

In the case of 559 the frequency array is filled with NaNs rather than the actual frequency after the first 3 measurements. I bet this is the reason for #397 too

@jenshnielsen
Copy link
Collaborator

I.e. do something like:

import qcodes as qc
import matplotlib.pyplot as plt
loaded_data = qc.load_data("VNA_power_set_frequency.dat")
fig, ax = plt.subplots(1,2)
ax[0].plot(loaded_data.frequency[0])
ax[1].plot(loaded_data.frequency[3])
fig.tight_layout()

and notice that the second plot is empty because all the data is Not a Number (NaN)

@nataliejpg
Copy link
Contributor

yh that was something I noticed which sometimes happens he VNA driver (and promptly forgot about), it usually doesn't matter because its a setpoint array that we make up so will be the same array for each trace but I also have no clear idea at all why it sometimes doesnt woek considering that the driver should set these arrays for every trace... I have some doubts that it's the same as #397 because that can be 'solved' by increasing the limit for nonlinearity a bit as @MerlinSmiles suggested which I wouldn't expect to allow it to plot if it was because of NaN problems, also if it was that then why would it be ok live plotting it but not loading it in afterwards? I can look around briefly for a data set without NaNs though and see if it can plot that though as a check for that being the reason for this bug

@jenshnielsen
Copy link
Collaborator

This can be reproduces relatively simply with a mock instrument

%matplotlib nbagg
import matplotlib.pyplot as plt
import numpy as np
import qcodes as qc
from toymodel import AModel, MockGates, MockSource, MockMeter, AverageAndRaw, ArrayGetter

# now create this "experiment", note that all these are instruments 
model = AModel()
gates = MockGates('gates', model=model)
source = MockSource('source', model=model)
meter = MockMeter('meter', model=model)

# The station is a container for all instruments that makes it easy 
# to log meta-data
station = qc.Station(gates, source, meter)

# it's nice to have the key parameters be part of the global namespace
# that way they're objects that we can easily set, get, and slice
c0, c1, c2, vsd = gates.chan0, gates.chan1, gates.chan2, source.amplitude
loop = qc.Loop(c0.sweep(0,20,0.1), delay=0.001).each(ArrayGetter(meter.amplitude, c2[-10:10:0.2], 0.001))
data = loop.get_data_set(name='testsweep')
plot = qc.MatPlot()
plot.add(data.meter_amplitude)
_ = loop.with_bg_task(plot.update).run()
plot2 = qc.MatPlot()
plot2.add(data.meter_amplitude)

However it only happens with the background task updating a plot. Removing the background task or replacing it with a dumme task seems to fix the issue.

@jenshnielsen
Copy link
Collaborator

So the problem is that the update function calls dataset.sync which ends up rereading the datafile from disk. This overwrites the dataset which already has all the hard arraylike setpoints defined with the on disk version which only has the setpoint arrays for already measured values. I think this can be work around by passing a dummy update function to plot.add.

Something like

def dummy_sync():
    pass

%matplotlib nbagg
import matplotlib.pyplot as plt
import numpy as np
import qcodes as qc
from toymodel import AModel, MockGates, MockSource, MockMeter, AverageAndRaw, ArrayGetter

# now create this "experiment", note that all these are instruments 
model = AModel()
gates = MockGates('gates', model=model)
source = MockSource('source', model=model)
meter = MockMeter('meter', model=model)

# The station is a container for all instruments that makes it easy 
# to log meta-data
station = qc.Station(gates, source, meter)

# it's nice to have the key parameters be part of the global namespace
# that way they're objects that we can easily set, get, and slice
c0, c1, c2, vsd = gates.chan0, gates.chan1, gates.chan2, source.amplitude
loop = qc.Loop(c0.sweep(0,20,0.1), delay=0.001).each(ArrayGetter(meter.amplitude, c2[-10:10:0.2], 0.001))
data = loop.get_data_set(name='testsweep')
plot = qc.MatPlot()
plot.add(data.meter_amplitude, updater=dummy_sync)
_ = loop.with_bg_task(plot.update).run()
plot2 = qc.MatPlot()
plot2.add(data.meter_amplitude)

does not reproduce the issue

@nataliejpg
Copy link
Contributor

@jenshnielsen, thanks for this. Do you have ideas for a 'non workaround' fix?

@jenshnielsen
Copy link
Collaborator

We agreed to remove the sync from the default update function. I will make that change today and we can push a new release with that fix soon.

jenshnielsen referenced this issue in jenshnielsen/Qcodes Dec 19, 2016
Dont sync a data set from disk if containing preset arrays as these will be overwritten
jenshnielsen referenced this issue in jenshnielsen/Qcodes Dec 19, 2016
fixes #380 by avoiding to overwrite data
with partial data from disk
jenshnielsen referenced this issue in jenshnielsen/Qcodes Dec 19, 2016
To restore the original functionality add updater='sync',
Fixes #380
jenshnielsen referenced this issue in jenshnielsen/Qcodes Jan 12, 2017
giulioungaretti pushed a commit that referenced this issue Jan 17, 2017
fixes #380 by avoiding to overwrite data
with partial data from disk
giulioungaretti pushed a commit that referenced this issue Jan 17, 2017
bors bot added a commit that referenced this issue Sep 6, 2022
4559: Update towncrier requirement from ~=21.9.0 to ~=22.8.0 r=jenshnielsen a=dependabot[bot]

Updates the requirements on [towncrier](https://github.com/hawkowl/towncrier) to permit the latest version.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/hawkowl/towncrier/releases">towncrier's releases</a>.</em></p>
<blockquote>
<h2>Towncrier 22.8.0</h2>
<h1>towncrier 22.8.0 (2022-08-29)</h1>
<p>No significant changes since the previous release candidate.</p>
<h1>towncrier 22.8.0.rc1 (2022-08-28)</h1>
<h2>Features</h2>
<ul>
<li>
<p>Make the check subcommand succeed for branches that change the news file</p>
<p>This should enable the <code>check</code> subcommand to be used as a CI lint step and
not fail when a pull request only modifies the configured news file (i.e. when
the news file is being assembled for the next release). (<code>[#337](twisted/towncrier#337) &lt;https://github.com/hawkowl/towncrier/issues/337&gt;</code>_)</p>
</li>
<li>
<p>Added support to tables in toml settings, which provides a more intuitive
way to configure custom types. (<code>[#369](twisted/towncrier#369) &lt;https://github.com/hawkowl/towncrier/issues/369&gt;</code>_)</p>
</li>
<li>
<p>The <code>towncrier create</code> command line now has a new <code>-m TEXT</code> argument that is used to define the content of the newly created fragment. (<code>[#374](twisted/towncrier#374) &lt;https://github.com/hawkowl/towncrier/issues/374&gt;</code>_)</p>
</li>
</ul>
<h2>Bugfixes</h2>
<ul>
<li>
<p>The extra newline between the title and rendered content when using <code>--draft</code> is no longer inserted. (<code>[#105](twisted/towncrier#105) &lt;https://github.com/hawkowl/towncrier/issues/105&gt;</code>_)</p>
</li>
<li>
<p>The detection of duplicate release notes was fixed and recording changes of same version is no longer triggered.</p>
<p>Support for having the release notes for each version in a separate file is working again. This is a regression introduced in VERSION 19.9.0rc1. (<code>[#391](twisted/towncrier#391) &lt;https://github.com/hawkowl/towncrier/issues/391&gt;</code>_)</p>
</li>
</ul>
<h2>Improved Documentation</h2>
<ul>
<li>Improve <code>CONTRIBUTING.rst</code> and add PR template. (<code>[#342](twisted/towncrier#342) &lt;https://github.com/hawkowl/towncrier/issues/342&gt;</code>_)</li>
<li>Move docs too the main branch and document custom fragment types. (<code>[#367](twisted/towncrier#367) &lt;https://github.com/hawkowl/towncrier/issues/367&gt;</code>_)</li>
<li>The CLI help messages were updated to contain more information. (<code>[#384](twisted/towncrier#384) &lt;https://github.com/hawkowl/towncrier/issues/384&gt;</code>_)</li>
</ul>
<h2>Deprecations and Removals</h2>
<ul>
<li>Support for all Python versions older than 3.7 has been dropped. (<code>[#378](twisted/towncrier#378) &lt;https://github.com/hawkowl/towncrier/issues/378&gt;</code>_)</li>
</ul>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/twisted/towncrier/blob/trunk/NEWS.rst">towncrier's changelog</a>.</em></p>
<blockquote>
<h1>towncrier 22.8.0 (2022-08-29)</h1>
<p>No significant changes since the previous release candidate.</p>
<h1>towncrier 22.8.0.rc1 (2022-08-28)</h1>
<h2>Features</h2>
<ul>
<li>
<p>Make the check subcommand succeed for branches that change the news file</p>
<p>This should enable the <code>check</code> subcommand to be used as a CI lint step and
not fail when a pull request only modifies the configured news file (i.e. when
the news file is being assembled for the next release). (<code>[#337](twisted/towncrier#337) &lt;https://github.com/hawkowl/towncrier/issues/337&gt;</code>_)</p>
</li>
<li>
<p>Added support to tables in toml settings, which provides a more intuitive
way to configure custom types. (<code>[#369](twisted/towncrier#369) &lt;https://github.com/hawkowl/towncrier/issues/369&gt;</code>_)</p>
</li>
<li>
<p>The <code>towncrier create</code> command line now has a new <code>-m TEXT</code> argument that is used to define the content of the newly created fragment. (<code>[#374](twisted/towncrier#374) &lt;https://github.com/hawkowl/towncrier/issues/374&gt;</code>_)</p>
</li>
</ul>
<h2>Bugfixes</h2>
<ul>
<li>
<p>The extra newline between the title and rendered content when using <code>--draft</code> is no longer inserted. (<code>[#105](twisted/towncrier#105) &lt;https://github.com/hawkowl/towncrier/issues/105&gt;</code>_)</p>
</li>
<li>
<p>The detection of duplicate release notes was fixed and recording changes of same version is no longer triggered.</p>
<p>Support for having the release notes for each version in a separate file is working again. This is a regression introduced in VERSION 19.9.0rc1. (<code>[#391](twisted/towncrier#391) &lt;https://github.com/hawkowl/towncrier/issues/391&gt;</code>_)</p>
</li>
</ul>
<h2>Improved Documentation</h2>
<ul>
<li>Improve <code>CONTRIBUTING.rst</code> and add PR template. (<code>[#342](twisted/towncrier#342) &lt;https://github.com/hawkowl/towncrier/issues/342&gt;</code>_)</li>
<li>Move docs too the main branch and document custom fragment types. (<code>[#367](twisted/towncrier#367) &lt;https://github.com/hawkowl/towncrier/issues/367&gt;</code>_)</li>
<li>The CLI help messages were updated to contain more information. (<code>[#384](twisted/towncrier#384) &lt;https://github.com/hawkowl/towncrier/issues/384&gt;</code>_)</li>
</ul>
<h2>Deprecations and Removals</h2>
<ul>
<li>Support for all Python versions older than 3.7 has been dropped. (<code>[#378](twisted/towncrier#378) &lt;https://github.com/hawkowl/towncrier/issues/378&gt;</code>_)</li>
</ul>
<h2>Misc</h2>
<ul>
<li><code>[#292](twisted/towncrier#292) &lt;https://github.com/hawkowl/towncrier/issues/292&gt;</code><em>, <code>[#330](twisted/towncrier#330) &lt;https://github.com/hawkowl/towncrier/issues/330&gt;</code></em>, <code>[#366](twisted/towncrier#366) &lt;https://github.com/hawkowl/towncrier/issues/366&gt;</code><em>, <code>[#376](twisted/towncrier#376) &lt;https://github.com/hawkowl/towncrier/issues/376&gt;</code></em>, <code>[#377](twisted/towncrier#377) &lt;https://github.com/hawkowl/towncrier/issues/377&gt;</code><em>, <code>[#380](twisted/towncrier#380) &lt;https://github.com/hawkowl/towncrier/issues/380&gt;</code></em>, <code>[#381](twisted/towncrier#381) &lt;https://github.com/hawkowl/towncrier/issues/381&gt;</code><em>, <code>[#382](twisted/towncrier#382) &lt;https://github.com/hawkowl/towncrier/issues/382&gt;</code></em>, <code>[#383](twisted/towncrier#383) &lt;https://github.com/hawkowl/towncrier/issues/383&gt;</code><em>, <code>[#393](twisted/towncrier#393) &lt;https://github.com/hawkowl/towncrier/issues/393&gt;</code></em>, <code>[#399](twisted/towncrier#399) &lt;https://github.com/hawkowl/towncrier/issues/399&gt;</code><em>, <code>[#402](twisted/towncrier#402) &lt;https://github.com/hawkowl/towncrier/issues/402&gt;</code></em></li>
</ul>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/twisted/towncrier/commit/411f2676b18daf9ba1eb656f7dc6c726397c4a9e"><code>411f267</code></a> Update version for final release.</li>
<li><a href="https://github.com/twisted/towncrier/commit/f031dfa94e52e07b6c71e88cd5cd50e3803ad96c"><code>f031dfa</code></a> towncrier build --yes</li>
<li><a href="https://github.com/twisted/towncrier/commit/4c854f58a2074458cd66767aca9f3aaa34d842d8"><code>4c854f5</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/hawkowl/towncrier/issues/402">#402</a> from webknjaz/patch-2</li>
<li><a href="https://github.com/twisted/towncrier/commit/f911402b69960bee358b0c2011d685721afa9454"><code>f911402</code></a> Pin external github actions,</li>
<li><a href="https://github.com/twisted/towncrier/commit/a814202234214182855fe4a5ffb40c7f7aec2b04"><code>a814202</code></a> [pre-commit.ci] auto fixes from pre-commit.com hooks</li>
<li><a href="https://github.com/twisted/towncrier/commit/675219a6deac7c65bb94b72da55059b7077e5ec4"><code>675219a</code></a> Add a dummy change note for PR <a href="https://github-redirect.dependabot.com/hawkowl/towncrier/issues/402">#402</a></li>
<li><a href="https://github.com/twisted/towncrier/commit/b566bfb0dcdcd86fa9d349875eba15e647c06459"><code>b566bfb</code></a> Uninvent the wheel w/ <code>re-actors/alls-green</code> @ GHA</li>
<li><a href="https://github.com/twisted/towncrier/commit/5bf0a4653bb2adf52162550d436f1dc39f6e0446"><code>5bf0a46</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/hawkowl/towncrier/issues/396">#396</a> from twisted/292-more-ci-checks</li>
<li><a href="https://github.com/twisted/towncrier/commit/1bb62219a9e7b0d969292cae56104678b8bea151"><code>1bb6221</code></a> Merge branch 'trunk' into 292-more-ci-checks</li>
<li><a href="https://github.com/twisted/towncrier/commit/07baa2ba4b1159462dcb212395be1de91674698d"><code>07baa2b</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/hawkowl/towncrier/issues/395">#395</a> from twisted/384-cli-help</li>
<li>Additional commits viewable in <a href="https://github.com/hawkowl/towncrier/compare/21.9.0...22.8.0">compare view</a></li>
</ul>
</details>
<br />


You can trigger a rebase of this PR by commenting ``@dependabot` rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- ``@dependabot` rebase` will rebase this PR
- ``@dependabot` recreate` will recreate this PR, overwriting any edits that have been made to it
- ``@dependabot` merge` will merge this PR after your CI passes on it
- ``@dependabot` squash and merge` will squash and merge this PR after your CI passes on it
- ``@dependabot` cancel merge` will cancel a previously requested merge and block automerging
- ``@dependabot` reopen` will reopen this PR if it is closed
- ``@dependabot` close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- ``@dependabot` ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- ``@dependabot` ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- ``@dependabot` ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>

Changes needed for this

* Invert logic for single file. 22.8.0 fixed the logic such that single_file=False is correct when you have more than one file
* Pin versions of towncrier and sphinx towncrier to reflect this (so we get the right config)


Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Jens H. Nielsen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants