Skip to content

Commit

Permalink
Merge #4759 #4773 #4779
Browse files Browse the repository at this point in the history
4759: Add ability to get parameter after set to dond r=jenshnielsen a=jenshnielsen

For some instruments it may be a good idea to get the value after setting it and store that in the dataset rather than relying on the instrument being able to set the exact value. 

This implements that by extending the Sweeps classes with a boolean. This could be extended to read a flag from the parameter giving the parameter a trait to indicate if it has been set


This is also a small step towards fixing #4695 since it will become possible to get the value of a parameter that one sets

To make this easier to demonstrate ManualParameters have been improved to log using the instrument logger

TODO 
- [x] Documentation (examples + docstrings)
- [x] Tests
- [x] release notes

4773: Update pillow requirement from ~=9.2.0 to ~=9.3.0 r=jenshnielsen a=dependabot[bot]

Updates the requirements on [pillow](https://github.com/python-pillow/Pillow) to permit the latest version.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/python-pillow/Pillow/releases">pillow's releases</a>.</em></p>
<blockquote>
<h2>9.3.0</h2>
<p><a href="https://pillow.readthedocs.io/en/stable/releasenotes/9.3.0.html">https://pillow.readthedocs.io/en/stable/releasenotes/9.3.0.html</a></p>
<h2>Changes</h2>
<ul>
<li>Initialize libtiff buffer when saving <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6699">#6699</a> [<a href="https://github.com/radarhere"><code>`@​radarhere</code></a>]</li>`
<li>Limit SAMPLESPERPIXEL to avoid runtime DOS <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6700">#6700</a> [<a href="https://github.com/wiredfool"><code>`@​wiredfool</code></a>]</li>`
<li>Inline fname2char to fix memory leak <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6329">#6329</a> [<a href="https://github.com/nulano"><code>`@​nulano</code></a>]</li>`
<li>Fix memory leaks related to text features <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6330">#6330</a> [<a href="https://github.com/nulano"><code>`@​nulano</code></a>]</li>`
<li>Use double quotes for version check on old CPython on Windows <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6695">#6695</a> [<a href="https://github.com/hugovk"><code>`@​hugovk</code></a>]</li>`
<li>GHA: replace deprecated set-output command with GITHUB_OUTPUT file <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6697">#6697</a> [<a href="https://github.com/nulano"><code>`@​nulano</code></a>]</li>`
<li>Remove backup implementation of Round for Windows platforms <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6693">#6693</a> [<a href="https://github.com/cgohlke"><code>`@​cgohlke</code></a>]</li>`
<li>Upload fribidi.dll to GitHub Actions <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6532">#6532</a> [<a href="https://github.com/nulano"><code>`@​nulano</code></a>]</li>`
<li>Fixed set_variation_by_name offset <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6445">#6445</a> [<a href="https://github.com/radarhere"><code>`@​radarhere</code></a>]</li>`
<li>Windows build improvements <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6562">#6562</a> [<a href="https://github.com/nulano"><code>`@​nulano</code></a>]</li>`
<li>Fix malloc in _imagingft.c:font_setvaraxes <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6690">#6690</a> [<a href="https://github.com/cgohlke"><code>`@​cgohlke</code></a>]</li>`
<li>Only use ASCII characters in C source file <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6691">#6691</a> [<a href="https://github.com/cgohlke"><code>`@​cgohlke</code></a>]</li>`
<li>Release Python GIL when converting images using matrix operations <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6418">#6418</a> [<a href="https://github.com/hmaarrfk"><code>`@​hmaarrfk</code></a>]</li>`
<li>Added ExifTags enums <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6630">#6630</a> [<a href="https://github.com/radarhere"><code>`@​radarhere</code></a>]</li>`
<li>Do not modify previous frame when calculating delta in PNG <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6683">#6683</a> [<a href="https://github.com/radarhere"><code>`@​radarhere</code></a>]</li>`
<li>Added support for reading BMP images with RLE4 compression <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6674">#6674</a> [<a href="https://github.com/npjg"><code>`@​npjg</code></a>]</li>`
<li>Decode JPEG compressed BLP1 data in original mode <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6678">#6678</a> [<a href="https://github.com/radarhere"><code>`@​radarhere</code></a>]</li>`
<li>pylint warnings <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6659">#6659</a> [<a href="https://github.com/marksmayo"><code>`@​marksmayo</code></a>]</li>`
<li>Added GPS TIFF tag info <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6661">#6661</a> [<a href="https://github.com/radarhere"><code>`@​radarhere</code></a>]</li>`
<li>Added conversion between RGB/RGBA/RGBX and LAB <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6647">#6647</a> [<a href="https://github.com/radarhere"><code>`@​radarhere</code></a>]</li>`
<li>Do not attempt normalization if mode is already normal <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6644">#6644</a> [<a href="https://github.com/radarhere"><code>`@​radarhere</code></a>]</li>`
<li>Fixed seeking to an L frame in a GIF <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6576">#6576</a> [<a href="https://github.com/radarhere"><code>`@​radarhere</code></a>]</li>`
<li>Consider all frames when selecting mode for PNG save_all <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6610">#6610</a> [<a href="https://github.com/radarhere"><code>`@​radarhere</code></a>]</li>`
<li>Don't reassign crc on ChunkStream close <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6627">#6627</a> [<a href="https://github.com/radarhere"><code>`@​radarhere</code></a>]</li>`
<li>Raise a warning if NumPy failed to raise an error during conversion <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6594">#6594</a> [<a href="https://github.com/radarhere"><code>`@​radarhere</code></a>]</li>`
<li>Only read a maximum of 100 bytes at a time in IMT header <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6623">#6623</a> [<a href="https://github.com/radarhere"><code>`@​radarhere</code></a>]</li>`
<li>Show all frames in ImageShow <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6611">#6611</a> [<a href="https://github.com/radarhere"><code>`@​radarhere</code></a>]</li>`
<li>Allow FLI palette chunk to not be first <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6626">#6626</a> [<a href="https://github.com/radarhere"><code>`@​radarhere</code></a>]</li>`
<li>If first GIF frame has transparency for RGB_ALWAYS loading strategy, use RGBA mode <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6592">#6592</a> [<a href="https://github.com/radarhere"><code>`@​radarhere</code></a>]</li>`
<li>Round box position to integer when pasting embedded color <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6517">#6517</a> [<a href="https://github.com/radarhere"><code>`@​radarhere</code></a>]</li>`
<li>Removed EXIF prefix when saving WebP <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6582">#6582</a> [<a href="https://github.com/radarhere"><code>`@​radarhere</code></a>]</li>`
<li>Pad IM palette to 768 bytes when saving <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6579">#6579</a> [<a href="https://github.com/radarhere"><code>`@​radarhere</code></a>]</li>`
<li>Added DDS BC6H reading <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6449">#6449</a> [<a href="https://github.com/ShadelessFox"><code>`@​ShadelessFox</code></a>]</li>`
<li>Added support for opening WhiteIsZero 16-bit integer TIFF images <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6642">#6642</a> [<a href="https://github.com/JayWiz"><code>`@​JayWiz</code></a>]</li>`
<li>Raise an error when allocating translucent color to RGB palette <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6654">#6654</a> [<a href="https://github.com/jsbueno"><code>`@​jsbueno</code></a>]</li>`
<li>Moved mode check outside of loops <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6650">#6650</a> [<a href="https://github.com/radarhere"><code>`@​radarhere</code></a>]</li>`
<li>Added reading of TIFF child images <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6569">#6569</a> [<a href="https://github.com/radarhere"><code>`@​radarhere</code></a>]</li>`
<li>Improved ImageOps palette handling <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6596">#6596</a> [<a href="https://github.com/PososikTeam"><code>`@​PososikTeam</code></a>]</li>`
<li>Defer parsing of palette into colors <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6567">#6567</a> [<a href="https://github.com/radarhere"><code>`@​radarhere</code></a>]</li>`
<li>Apply transparency to P images in ImageTk.PhotoImage <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6559">#6559</a> [<a href="https://github.com/radarhere"><code>`@​radarhere</code></a>]</li>`
<li>Use rounding in ImageOps contain() and pad() <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6522">#6522</a> [<a href="https://github.com/bibinhashley"><code>`@​bibinhashley</code></a>]</li>`
<li>Fixed GIF remapping to palette with duplicate entries <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6548">#6548</a> [<a href="https://github.com/radarhere"><code>`@​radarhere</code></a>]</li>`
<li>Allow remap_palette() to return an image with less than 256 palette entries <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6543">#6543</a> [<a href="https://github.com/radarhere"><code>`@​radarhere</code></a>]</li>`
<li>Corrected BMP and TGA palette size when saving <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6500">#6500</a> [<a href="https://github.com/radarhere"><code>`@​radarhere</code></a>]</li>`
</ul>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/python-pillow/Pillow/blob/main/CHANGES.rst">pillow's changelog</a>.</em></p>
<blockquote>
<h2>9.3.0 (2022-10-29)</h2>
<ul>
<li>
<p>Limit SAMPLESPERPIXEL to avoid runtime DOS <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6700">#6700</a>
[wiredfool]</p>
</li>
<li>
<p>Initialize libtiff buffer when saving <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6699">#6699</a>
[radarhere]</p>
</li>
<li>
<p>Inline fname2char to fix memory leak <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6329">#6329</a>
[nulano]</p>
</li>
<li>
<p>Fix memory leaks related to text features <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6330">#6330</a>
[nulano]</p>
</li>
<li>
<p>Use double quotes for version check on old CPython on Windows <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6695">#6695</a>
[hugovk]</p>
</li>
<li>
<p>Remove backup implementation of Round for Windows platforms <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6693">#6693</a>
[cgohlke]</p>
</li>
<li>
<p>Fixed set_variation_by_name offset <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6445">#6445</a>
[radarhere]</p>
</li>
<li>
<p>Fix malloc in _imagingft.c:font_setvaraxes <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6690">#6690</a>
[cgohlke]</p>
</li>
<li>
<p>Release Python GIL when converting images using matrix operations <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6418">#6418</a>
[hmaarrfk]</p>
</li>
<li>
<p>Added ExifTags enums <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6630">#6630</a>
[radarhere]</p>
</li>
<li>
<p>Do not modify previous frame when calculating delta in PNG <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6683">#6683</a>
[radarhere]</p>
</li>
<li>
<p>Added support for reading BMP images with RLE4 compression <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6674">#6674</a>
[npjg, radarhere]</p>
</li>
<li>
<p>Decode JPEG compressed BLP1 data in original mode <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6678">#6678</a>
[radarhere]</p>
</li>
<li>
<p>Added GPS TIFF tag info <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6661">#6661</a>
[radarhere]</p>
</li>
<li>
<p>Added conversion between RGB/RGBA/RGBX and LAB <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6647">#6647</a>
[radarhere]</p>
</li>
<li>
<p>Do not attempt normalization if mode is already normal <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6644">#6644</a>
[radarhere]</p>
</li>
</ul>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/python-pillow/Pillow/commit/d594f4cb8dc47fb0c69ae58d9fff86faae4515bd"><code>d594f4c</code></a> Update CHANGES.rst [ci skip]</li>
<li><a href="https://github.com/python-pillow/Pillow/commit/909dc64ed5f676169aa3d9b0c26f132a06321b83"><code>909dc64</code></a> 9.3.0 version bump</li>
<li><a href="https://github.com/python-pillow/Pillow/commit/1a51ce7b955c65c8f2c6bc7772735b197b8a6aa3"><code>1a51ce7</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6699">#6699</a> from hugovk/security-libtiff_buffer</li>
<li><a href="https://github.com/python-pillow/Pillow/commit/2444cddab2f83f28687c7c20871574acbb6dbcf3"><code>2444cdd</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/python-pillow/Pillow/issues/6700">#6700</a> from hugovk/security-samples_per_pixel-sec</li>
<li><a href="https://github.com/python-pillow/Pillow/commit/744f455830871d61a8de0a5e629d4c2e33817cbb"><code>744f455</code></a> Added release notes</li>
<li><a href="https://github.com/python-pillow/Pillow/commit/0846bfae48513f2f51ca8547ed3b8954fa501fda"><code>0846bfa</code></a> Add to release notes</li>
<li><a href="https://github.com/python-pillow/Pillow/commit/799a6a01052cea3f417a571d7c64cd14acc18c64"><code>799a6a0</code></a> Fix linting</li>
<li><a href="https://github.com/python-pillow/Pillow/commit/00b25fd3ac3648bc28eff5d4c4d816e605e3f05f"><code>00b25fd</code></a> Hide UserWarning in logs</li>
<li><a href="https://github.com/python-pillow/Pillow/commit/05b175ef88c22f5c416bc9b8d5b897dea1abbf2c"><code>05b175e</code></a> Tighter test case</li>
<li><a href="https://github.com/python-pillow/Pillow/commit/13f2c5ae14901c89c38f898496102afd9daeaf6d"><code>13f2c5a</code></a> Prevent DOS with large SAMPLESPERPIXEL in Tiff IFD</li>
<li>Additional commits viewable in <a href="https://github.com/python-pillow/Pillow/compare/9.2.0...9.3.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>

4779: Keithley calibration: adjust calibration date before saving new calibration r=jenshnielsen a=michieldemoor

When running the calibrate_keithley_smu_v method to calibrate a Keithley SMU, as documented [here](https://qcodes.github.io/Qcodes/examples/driver_examples/Qcodes%20example%20with%20Keithley%202600.html#Recalibration), the calibration gives the following error:

ERROR CODE: 5029

SMU A: Cannot save without changing cal adjustment date

SMU B: Cannot save without changing cal adjustment date

This PR addresses this error by changing the calibration adjustment date before saving the new calibration.

Co-authored-by: Jens H. Nielsen <Jens.Nielsen@microsoft.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: mdemoor <mdemoor@microsoft.com>
Co-authored-by: Mikhail Astafev <astafan8@gmail.com>
  • Loading branch information
5 people committed Oct 31, 2022
4 parents 2459ba8 + f57eadb + 26a37f8 + 5ca4325 commit d9dcdf9
Show file tree
Hide file tree
Showing 11 changed files with 654 additions and 2,777 deletions.
2 changes: 2 additions & 0 deletions docs/changes/newsfragments/4759.improved
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The sweeps used by doNd has gained the ability to perform a get call after setting the parameter and storing
that value in the dataset rather than the value set.
1 change: 1 addition & 0 deletions docs/changes/newsfragments/4779.improved
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Keithley calibration: adjust calibration date before saving new calibration

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions qcodes/calibrations/keithley.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ def setup_dmm(dmm: Instrument) -> None:


def save_calibration(smu: Keithley_2600) -> None:
calibration_date = int(time.time())
for smu_channel in smu.channels:
smu.write(f"{smu_channel.channel}.cal.adjustdate = {calibration_date}")
smu.write(f"{smu_channel.channel}.cal.save()")


Expand Down
7 changes: 6 additions & 1 deletion qcodes/dataset/dond/do_nd.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class ParameterSetEvent:
should_set: bool
delay: float
actions: ActionsT
get_after_set: bool


class _Sweeper:
Expand Down Expand Up @@ -228,6 +229,7 @@ def __getitem__(self, index: int) -> tuple[ParameterSetEvent, ...]:
should_set=should_set,
delay=sweep.delay,
actions=sweep.post_actions,
get_after_set=sweep.get_after_set,
)
parameter_set_events.append(event)
return tuple(parameter_set_events)
Expand Down Expand Up @@ -708,7 +710,10 @@ def dond(
act()
time.sleep(set_event.delay)

results[set_event.parameter] = set_event.new_value
if set_event.get_after_set:
results[set_event.parameter] = set_event.parameter()
else:
results[set_event.parameter] = set_event.new_value

meas_value_pair = call_params_meas()
for meas_param, value in meas_value_pair:
Expand Down
39 changes: 38 additions & 1 deletion qcodes/dataset/dond/sweeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ def post_actions(self) -> ActionsT:
"""
pass

@property
def get_after_set(self) -> bool:
"""
Should we perform a call to get on the parameter after setting it
and store that rather than the setpoint value in the dataset?
This defaults to False for backwards compatibility
but subclasses should overwrite this to implement if correctly.
"""
return False


class LinSweep(AbstractSweep[np.float64]):
"""
Expand All @@ -67,7 +78,10 @@ class LinSweep(AbstractSweep[np.float64]):
start: Sweep start value.
stop: Sweep end value.
num_points: Number of sweep points.
delay: Time in seconds between two consecutive sweep points
delay: Time in seconds between two consecutive sweep points.
post_actions: Actions to do after each sweep point.
get_after_set: Should we perform a get on the parameter after setting it
and store the value returned by get rather than the set value in the dataset.
"""

def __init__(
Expand All @@ -78,13 +92,15 @@ def __init__(
num_points: int,
delay: float = 0,
post_actions: ActionsT = (),
get_after_set: bool = False,
):
self._param = param
self._start = start
self._stop = stop
self._num_points = num_points
self._delay = delay
self._post_actions = post_actions
self._get_after_set = get_after_set

def get_setpoints(self) -> npt.NDArray[np.float64]:
"""
Expand All @@ -109,6 +125,10 @@ def num_points(self) -> int:
def post_actions(self) -> ActionsT:
return self._post_actions

@property
def get_after_set(self) -> bool:
return self._get_after_set


class LogSweep(AbstractSweep[np.float64]):
"""
Expand All @@ -120,6 +140,9 @@ class LogSweep(AbstractSweep[np.float64]):
stop: Sweep end value.
num_points: Number of sweep points.
delay: Time in seconds between two consecutive sweep points.
post_actions: Actions to do after each sweep point.
get_after_set: Should we perform a get on the parameter after setting it
and store the value returned by get rather than the set value in the dataset.
"""

def __init__(
Expand All @@ -130,13 +153,15 @@ def __init__(
num_points: int,
delay: float = 0,
post_actions: ActionsT = (),
get_after_set: bool = False,
):
self._param = param
self._start = start
self._stop = stop
self._num_points = num_points
self._delay = delay
self._post_actions = post_actions
self._get_after_set = get_after_set

def get_setpoints(self) -> npt.NDArray[np.float64]:
"""
Expand All @@ -161,6 +186,10 @@ def num_points(self) -> int:
def post_actions(self) -> ActionsT:
return self._post_actions

@property
def get_after_set(self) -> bool:
return self._get_after_set


class ArraySweep(AbstractSweep, Generic[T]):
"""
Expand All @@ -171,6 +200,8 @@ class ArraySweep(AbstractSweep, Generic[T]):
array: array with values to sweep.
delay: Time in seconds between two consecutive sweep points.
post_actions: Actions to do after each sweep point.
get_after_set: Should we perform a get on the parameter after setting it
and store the value returned by get rather than the set value in the dataset.
"""

def __init__(
Expand All @@ -179,11 +210,13 @@ def __init__(
array: Sequence[Any] | npt.NDArray[T],
delay: float = 0,
post_actions: ActionsT = (),
get_after_set: bool = False,
):
self._param = param
self._array = np.array(array)
self._delay = delay
self._post_actions = post_actions
self._get_after_set = get_after_set

def get_setpoints(self) -> npt.NDArray[T]:
return self._array
Expand All @@ -204,6 +237,10 @@ def num_points(self) -> int:
def post_actions(self) -> ActionsT:
return self._post_actions

@property
def get_after_set(self) -> bool:
return self._get_after_set


class TogetherSweep:
"""
Expand Down
3 changes: 2 additions & 1 deletion qcodes/instrument/instrument_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

if TYPE_CHECKING:
from qcodes.instrument.channel import ChannelTuple, InstrumentModule
from qcodes.logger.instrument_logger import InstrumentLoggerAdapter

from qcodes.utils import QCoDeSDeprecationWarning

Expand Down Expand Up @@ -82,7 +83,7 @@ def __init__(
# This is needed for snapshot method to work
self._meta_attrs = ["name", "label"]

self.log = get_instrument_logger(self, __name__)
self.log: InstrumentLoggerAdapter = get_instrument_logger(self, __name__)

@property
def label(self) -> str:
Expand Down
19 changes: 17 additions & 2 deletions qcodes/parameters/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

if TYPE_CHECKING:
from qcodes.instrument.base import InstrumentBase
from qcodes.logger.instrument_logger import InstrumentLoggerAdapter
from qcodes.validators import Validator


Expand Down Expand Up @@ -180,15 +181,29 @@ def __init__(
**kwargs: Any,
) -> None:
def _get_manual_parameter() -> ParamRawDataType:
log.debug(
if self.root_instrument is not None:
mylogger: InstrumentLoggerAdapter | logging.Logger = (
self.root_instrument.log
)
else:
mylogger = log
mylogger.debug(
"Getting raw value of parameter: %s as %s",
self.full_name,
self.cache.raw_value,
)
return self.cache.raw_value

def _set_manual_parameter(x: ParamRawDataType) -> ParamRawDataType:
log.debug("Setting raw value of parameter: %s to %s", self.full_name, x)
if self.root_instrument is not None:
mylogger: InstrumentLoggerAdapter | logging.Logger = (
self.root_instrument.log
)
else:
mylogger = log
mylogger.debug(
"Setting raw value of parameter: %s to %s", self.full_name, x
)
return x

if instrument is not None and bind_to_instrument:
Expand Down
118 changes: 118 additions & 0 deletions qcodes/tests/dataset/dond/test_doNd.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,50 @@
from qcodes.validators import Ints


class TrackingParameter(Parameter):
"""Parameter that keeps track of number of get and set operations"""

def __init__(self, *args, **kwargs):
self.set_count = 0
self.get_count = 0
super().__init__(*args, **kwargs)

def set_raw(self, value):
self.set_count += 1
self.cache._set_from_raw_value(value)

def get_raw(self):
self.get_count += 1
return self.cache.raw_value

def reset_count(self) -> None:
self.get_count = 0
self.set_count = 0


class GetReturnsCountParameter(Parameter):
"""Parameter that keeps track of number of get and set operations
Allows you to set a value but returns the get count rather
than the value"""

def __init__(self, *args, **kwargs):
self.set_count = 0
self.get_count = 0
super().__init__(*args, **kwargs)

def set_raw(self, value):
self.set_count += 1
self.cache._set_from_raw_value(value)

def get_raw(self):
self.get_count += 1
return self.get_count

def reset_count(self) -> None:
self.get_count = 0
self.set_count = 0


def test_linear_sweep_get_setpoints(_param):
start = 0
stop = 1
Expand Down Expand Up @@ -1589,3 +1633,77 @@ def test_default_log_info(caplog):
dond(LinSweep(param_1, 0, 10, 10), param_2)

assert "Using 'qcodes.dataset.dond'" in caplog.text


def test_dond_get_after_set(_param_set, _param_set_2, _param):

n_points = 10

a = TrackingParameter("a", initial_value=0)
b = TrackingParameter("b", initial_value=0)

a.reset_count()
b.reset_count()

assert a.get_count == 0
assert a.set_count == 0
assert b.get_count == 0
assert b.set_count == 0

dond(LinSweep(a, 0, 10, n_points, get_after_set=True), b)

assert a.get_count == n_points
assert a.set_count == n_points
assert b.get_count == n_points
assert b.set_count == 0


def test_dond_no_get_after_set(_param_set, _param_set_2, _param):

n_points = 10

a = TrackingParameter("a", initial_value=0)
b = TrackingParameter("b", initial_value=0)

a.reset_count()
b.reset_count()

assert a.get_count == 0
assert a.set_count == 0
assert b.get_count == 0
assert b.set_count == 0

dond(LinSweep(a, 0, 10, n_points, get_after_set=False), b)

assert a.get_count == 0
assert a.set_count == n_points
assert b.get_count == n_points
assert b.set_count == 0


def test_dond_get_after_set_stores_get_value(_param_set, _param_set_2, _param):

n_points = 11

a = GetReturnsCountParameter("a", initial_value=0)
b = TrackingParameter("b", initial_value=0)

a.reset_count()
b.reset_count()

assert a.get_count == 0
assert a.set_count == 0
assert b.get_count == 0
assert b.set_count == 0

ds, _, _ = dond(LinSweep(a, -10, -20, n_points, get_after_set=True), b)

# since we are using the GetReturnsCountParameter the sweep should be count e.g. 0, 1, ... 11
# not the set parameters -10, .. - 20
np.testing.assert_array_equal(
ds.get_parameter_data()["b"]["a"], np.linspace(1, 11, n_points)
)
assert a.get_count == n_points
assert a.set_count == n_points
assert b.get_count == n_points
assert b.set_count == 0
12 changes: 10 additions & 2 deletions qcodes/tests/instrument_mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,11 @@ def get_raw(self):
dac = self.root_instrument._setter_instr
val = self._ed.send(dac.ch1.cache.get())
next(self._ed)
log.debug("Getting raw value of parameter: %s as %s", self.full_name, val)
if self.root_instrument is not None:
mylogger = self.root_instrument.log
else:
mylogger = log
mylogger.debug("Getting raw value of parameter: %s as %s", self.full_name, val)
return val

@staticmethod
Expand Down Expand Up @@ -241,7 +245,11 @@ def get_raw(self):
dac = self.root_instrument._setter_instr
val = self._gauss.send((dac.ch1.cache.get(), dac.ch2.cache.get()))
next(self._gauss)
log.debug("Getting raw value of parameter: %s as %s", self.full_name, val)
if self.root_instrument is not None:
mylogger = self.root_instrument.log
else:
mylogger = log
mylogger.debug("Getting raw value of parameter: %s as %s", self.full_name, val)
return val

def _gauss_model(self):
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pandas~=1.5.1
pandocfilters~=1.5.0
parso~=0.8.3
pickleshare~=0.7.5
Pillow~=9.2.0
Pillow~=9.3.0
pluggy~=1.0.0
portalocker~=2.6.0
prometheus-client~=0.15.0
Expand Down

0 comments on commit d9dcdf9

Please sign in to comment.