Skip to content

Commit

Permalink
Merge branch 'main' into samanthaho/infer
Browse files Browse the repository at this point in the history
  • Loading branch information
samantha-ho authored Apr 26, 2024
2 parents da1645a + 51fcfa8 commit 9bee368
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 19 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ jobs:
egress-policy: audit

- name: Checkout repository
uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@8f596b4ae3cb3c588a5c46780b86dd53fef16c52 # v3.25.2
uses: github/codeql-action/init@d39d31e687223d841ef683f52467bd88e9b21c14 # v3.25.3
with:
languages: ${{ matrix.language }}

- name: Autobuild
uses: github/codeql-action/autobuild@8f596b4ae3cb3c588a5c46780b86dd53fef16c52 # v3.25.2
uses: github/codeql-action/autobuild@d39d31e687223d841ef683f52467bd88e9b21c14 # v3.25.3

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@8f596b4ae3cb3c588a5c46780b86dd53fef16c52 # v3.25.2
uses: github/codeql-action/analyze@d39d31e687223d841ef683f52467bd88e9b21c14 # v3.25.3
2 changes: 1 addition & 1 deletion .github/workflows/darker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
with:
egress-policy: audit

- uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
with:
fetch-depth: 0
- uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ jobs:
egress-policy: audit

- name: 'Checkout Repository'
uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
- name: 'Dependency Review'
uses: actions/dependency-review-action@5bbc3ba658137598168acb2ab73b21c432dd411b # v4.2.5
6 changes: 3 additions & 3 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
uses: step-security/harden-runner@63c24ba6bd7ba022e95695ff85de572c04a18142 # v2.7.0
with:
egress-policy: audit
- uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
with:
# we need full history with tags for the version number
fetch-depth: '0'
Expand Down Expand Up @@ -122,10 +122,10 @@ jobs:
with:
egress-policy: audit

- uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4

- name: Download artifact
uses: actions/download-artifact@9c19ed7fe5d278cd354c7dfd5d3b88589c7e2395 # v4.1.6
uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4.1.7
with:
name: docs_3.11_ubuntu-latest
path: build_docs
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ jobs:
with:
egress-policy: audit

- uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
- uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0
- uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
2 changes: 1 addition & 1 deletion .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
with:
egress-policy: audit

- uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
with:
submodules: true
# we need full history with tags for the version number
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/scorecards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
egress-policy: audit

- name: "Checkout code"
uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
with:
persist-credentials: false

Expand Down Expand Up @@ -71,6 +71,6 @@ jobs:

# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@8f596b4ae3cb3c588a5c46780b86dd53fef16c52 # v3.25.2
uses: github/codeql-action/upload-sarif@d39d31e687223d841ef683f52467bd88e9b21c14 # v3.25.3
with:
sarif_file: results.sarif
2 changes: 1 addition & 1 deletion .github/workflows/upload_to_pypi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
with:
egress-policy: audit

- uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
- name: Set up Python
uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0
with:
Expand Down
2 changes: 2 additions & 0 deletions docs/changes/newsfragments/6009.improved
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Station.get_component and Instrument.get_component has gained the ability to lookup a component
on an instrument that is only added as a member of a chanellist/tuple and not added as an individual component.
25 changes: 22 additions & 3 deletions src/qcodes/instrument/instrument_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,27 @@ def get_component(self, full_name: str) -> MetadatableWithName:
def _get_component_by_name(
self, potential_top_level_name: str, remaining_name_parts: list[str]
) -> MetadatableWithName:

log.debug(
"trying to find component %s on %s, remaining %s",
potential_top_level_name,
self.full_name,
remaining_name_parts,
)
component: MetadatableWithName | None = None

sub_component_name_map = {
sub_component.short_name: sub_component
for sub_component in self.submodules.values()
}

channel_name_map: dict[str, InstrumentModule] = {}
for channel_list in self._channel_lists.values():
local_channels_name_map: dict[str, InstrumentModule] = {
channel.short_name: channel for channel in channel_list
}
channel_name_map.update(local_channels_name_map.items())

if potential_top_level_name in self.parameters:
component = self.parameters[potential_top_level_name]
elif potential_top_level_name in self.functions:
Expand All @@ -283,13 +297,18 @@ def _get_component_by_name(
remaining_name = "_".join(remaining_name_parts)
component = component.get_component(remaining_name)
remaining_name_parts = []
elif potential_top_level_name in channel_name_map:
component = channel_name_map[potential_top_level_name]
if len(remaining_name_parts) > 0:
remaining_name_parts.reverse()
remaining_name = "_".join(remaining_name_parts)
component = component.get_component(remaining_name)
remaining_name_parts = []

if component is not None:
if len(remaining_name_parts) == 0:
return component

remaining_name_parts.reverse()

if len(remaining_name_parts) == 0:
raise KeyError(
f"Found component {self.full_name} but could not "
Expand All @@ -299,7 +318,7 @@ def _get_component_by_name(
new_potential_top_level_name = (
f"{potential_top_level_name}_{remaining_name_parts.pop()}"
)
remaining_name_parts.reverse()

component = self._get_component_by_name(
new_potential_top_level_name, remaining_name_parts
)
Expand Down
21 changes: 20 additions & 1 deletion src/qcodes/instrument_drivers/mock_instruments/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ def turn_on(self) -> None:
pass


class DummyChannelInstrument(Instrument):
class DummyChannelInstrument(DummyBase):
"""
Dummy instrument with channels
"""
Expand All @@ -474,6 +474,25 @@ def __init__(
self.add_submodule("channels", channels.to_channel_tuple())


class DummyChannelOnlyInstrument(DummyBase):
"""
Dummy instrument with channels that have not been added as individual submodules.
Also use module names with _ in them to check that we can handle that.
"""

def __init__(self, name: str, **kwargs: Any):
super().__init__(name, **kwargs)

channels = ChannelList(self, "Temp_Sensors", DummyChannel)
channel_ids: Sequence[str] = ("A_a", "B_b", "C_c", "D_d", "E_e", "F_f")
channel_names = tuple(f"Chan{chan_name}" for chan_name in channel_ids)

for chan_name, chan_id in zip(channel_names, channel_ids):
channel = DummyChannel(self, chan_name, chan_id)
channels.append(channel)
self.add_submodule("channels", channels.to_channel_tuple())


class MultiGetter(MultiParameter):
"""
Test parameters with complicated return values
Expand Down
11 changes: 10 additions & 1 deletion tests/test_station.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from qcodes.instrument import Instrument
from qcodes.instrument_drivers.mock_instruments import (
DummyChannelInstrument,
DummyChannelOnlyInstrument,
DummyInstrument,
)
from qcodes.monitor import Monitor
Expand Down Expand Up @@ -891,15 +892,23 @@ def test_station_config_created_with_multiple_config_files() -> None:

def test_get_component_by_name() -> None:
instr = DummyChannelInstrument(name="dummy")
instr2 = DummyChannelOnlyInstrument(name="some_other_dummy")
param = Parameter(name="param", set_cmd=None, get_cmd=None)
station = Station(instr, param)
station = Station(instr, instr2, param)

assert station.get_component("dummy") is instr
assert station.get_component("dummy_A") is instr.A
assert station.get_component("dummy_ChanA") is instr.A
assert station.get_component("dummy_A_temperature") is instr.A.temperature
assert station.get_component("dummy_ChanA_temperature") is instr.A.temperature

assert station.get_component("some_other_dummy") is instr2
assert station.get_component("some_other_dummy_ChanA_a") is instr2.channels[0]
assert (
station.get_component("some_other_dummy_ChanA_a_temperature")
is instr2.channels[0].temperature
)

assert station.get_component("param") is param


Expand Down

0 comments on commit 9bee368

Please sign in to comment.