|
34 | 34 | from qcodes.validators import Ints
|
35 | 35 |
|
36 | 36 |
|
| 37 | +class TrackingParameter(Parameter): |
| 38 | + """Parameter that keeps track of number of get and set operations""" |
| 39 | + |
| 40 | + def __init__(self, *args, **kwargs): |
| 41 | + self.set_count = 0 |
| 42 | + self.get_count = 0 |
| 43 | + super().__init__(*args, **kwargs) |
| 44 | + |
| 45 | + def set_raw(self, value): |
| 46 | + self.set_count += 1 |
| 47 | + self.cache._set_from_raw_value(value) |
| 48 | + |
| 49 | + def get_raw(self): |
| 50 | + self.get_count += 1 |
| 51 | + return self.cache.raw_value |
| 52 | + |
| 53 | + def reset_count(self) -> None: |
| 54 | + self.get_count = 0 |
| 55 | + self.set_count = 0 |
| 56 | + |
| 57 | + |
| 58 | +class GetReturnsCountParameter(Parameter): |
| 59 | + """Parameter that keeps track of number of get and set operations |
| 60 | + Allows you to set a value but returns the get count rather |
| 61 | + than the value""" |
| 62 | + |
| 63 | + def __init__(self, *args, **kwargs): |
| 64 | + self.set_count = 0 |
| 65 | + self.get_count = 0 |
| 66 | + super().__init__(*args, **kwargs) |
| 67 | + |
| 68 | + def set_raw(self, value): |
| 69 | + self.set_count += 1 |
| 70 | + self.cache._set_from_raw_value(value) |
| 71 | + |
| 72 | + def get_raw(self): |
| 73 | + self.get_count += 1 |
| 74 | + return self.get_count |
| 75 | + |
| 76 | + def reset_count(self) -> None: |
| 77 | + self.get_count = 0 |
| 78 | + self.set_count = 0 |
| 79 | + |
| 80 | + |
37 | 81 | def test_linear_sweep_get_setpoints(_param):
|
38 | 82 | start = 0
|
39 | 83 | stop = 1
|
@@ -1589,3 +1633,77 @@ def test_default_log_info(caplog):
|
1589 | 1633 | dond(LinSweep(param_1, 0, 10, 10), param_2)
|
1590 | 1634 |
|
1591 | 1635 | assert "Using 'qcodes.dataset.dond'" in caplog.text
|
| 1636 | + |
| 1637 | + |
| 1638 | +def test_dond_get_after_set(_param_set, _param_set_2, _param): |
| 1639 | + |
| 1640 | + n_points = 10 |
| 1641 | + |
| 1642 | + a = TrackingParameter("a", initial_value=0) |
| 1643 | + b = TrackingParameter("b", initial_value=0) |
| 1644 | + |
| 1645 | + a.reset_count() |
| 1646 | + b.reset_count() |
| 1647 | + |
| 1648 | + assert a.get_count == 0 |
| 1649 | + assert a.set_count == 0 |
| 1650 | + assert b.get_count == 0 |
| 1651 | + assert b.set_count == 0 |
| 1652 | + |
| 1653 | + dond(LinSweep(a, 0, 10, n_points, get_after_set=True), b) |
| 1654 | + |
| 1655 | + assert a.get_count == n_points |
| 1656 | + assert a.set_count == n_points |
| 1657 | + assert b.get_count == n_points |
| 1658 | + assert b.set_count == 0 |
| 1659 | + |
| 1660 | + |
| 1661 | +def test_dond_no_get_after_set(_param_set, _param_set_2, _param): |
| 1662 | + |
| 1663 | + n_points = 10 |
| 1664 | + |
| 1665 | + a = TrackingParameter("a", initial_value=0) |
| 1666 | + b = TrackingParameter("b", initial_value=0) |
| 1667 | + |
| 1668 | + a.reset_count() |
| 1669 | + b.reset_count() |
| 1670 | + |
| 1671 | + assert a.get_count == 0 |
| 1672 | + assert a.set_count == 0 |
| 1673 | + assert b.get_count == 0 |
| 1674 | + assert b.set_count == 0 |
| 1675 | + |
| 1676 | + dond(LinSweep(a, 0, 10, n_points, get_after_set=False), b) |
| 1677 | + |
| 1678 | + assert a.get_count == 0 |
| 1679 | + assert a.set_count == n_points |
| 1680 | + assert b.get_count == n_points |
| 1681 | + assert b.set_count == 0 |
| 1682 | + |
| 1683 | + |
| 1684 | +def test_dond_get_after_set_stores_get_value(_param_set, _param_set_2, _param): |
| 1685 | + |
| 1686 | + n_points = 11 |
| 1687 | + |
| 1688 | + a = GetReturnsCountParameter("a", initial_value=0) |
| 1689 | + b = TrackingParameter("b", initial_value=0) |
| 1690 | + |
| 1691 | + a.reset_count() |
| 1692 | + b.reset_count() |
| 1693 | + |
| 1694 | + assert a.get_count == 0 |
| 1695 | + assert a.set_count == 0 |
| 1696 | + assert b.get_count == 0 |
| 1697 | + assert b.set_count == 0 |
| 1698 | + |
| 1699 | + ds, _, _ = dond(LinSweep(a, -10, -20, n_points, get_after_set=True), b) |
| 1700 | + |
| 1701 | + # since we are using the GetReturnsCountParameter the sweep should be count e.g. 0, 1, ... 11 |
| 1702 | + # not the set parameters -10, .. - 20 |
| 1703 | + np.testing.assert_array_equal( |
| 1704 | + ds.get_parameter_data()["b"]["a"], np.linspace(1, 11, n_points) |
| 1705 | + ) |
| 1706 | + assert a.get_count == n_points |
| 1707 | + assert a.set_count == n_points |
| 1708 | + assert b.get_count == n_points |
| 1709 | + assert b.set_count == 0 |
0 commit comments