Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

### Changed

- Improved error messages in `OPXPlusPortsContainer` and `FEMPortsContainer`: invalid port types now raise `ValueError` immediately, and malformed port reference strings raise `ValueError` with a descriptive message instead of a cryptic unpacking error.
- **Breaking Change**: `set_at_reference()` method now defaults to `allow_non_reference=True` instead of `False`. This aligns with real-world usage patterns and improves developer experience. Users requiring error-by-default can explicitly pass `allow_non_reference=False`.
- **Breaking Change**: Default serialization behavior changed from excluding defaults to including them for more explicit state representation
- Config version bumped from v2 to v3
Expand Down
64 changes: 45 additions & 19 deletions quam/components/ports/ports_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ def _get_port(
create: bool = False,
**kwargs,
):
if port_type not in {
"analog_output",
"analog_input",
"digital_output",
"digital_input",
}:
raise ValueError(f"Invalid port type: {port_type}")

controllers = getattr(self, f"{port_type}s")

try:
Expand All @@ -78,8 +86,6 @@ def _get_port(
ports[port_id] = OPXPlusDigitalOutputPort(controller_id, port_id, **kwargs)
elif port_type == "digital_input":
ports[port_id] = OPXPlusDigitalInputPort(controller_id, port_id, **kwargs)
else:
raise ValueError(f"Invalid port type: {port_type}")

return ports[port_id]

Expand All @@ -94,13 +100,19 @@ def reference_to_port(
if reference is None:
raise ValueError("Cannot get port from reference {port_reference}")
port_reference = reference
elems = port_reference.split("/")
port_type, controller_id, port_id = elems[-3:]

port_type = port_type[:-1]
if controller_id.isdigit():
controller_id = int(controller_id)
port_id = int(port_id)
try:
elems = port_reference.split("/")
port_type, controller_id, port_id = elems[-3:]

port_type = port_type[:-1]
if controller_id.isdigit():
controller_id = int(controller_id)
port_id = int(port_id)
except Exception as e:
raise ValueError(
f"Unable to parse port reference for OPX+: {port_reference}"
) from e

return self._get_port(controller_id, port_id, port_type, create=create)

Expand Down Expand Up @@ -177,6 +189,15 @@ def _get_port(
create: bool = False,
**kwargs,
):
if port_type not in {
"analog_output",
"analog_input",
"mw_output",
"mw_input",
"digital_output",
}:
raise ValueError(f"Invalid port type: {port_type}")

controllers = getattr(self, f"{port_type}s")

try:
Expand Down Expand Up @@ -228,8 +249,6 @@ def _get_port(
ports[port_id] = FEMDigitalOutputPort(
controller_id, fem_id, port_id, **kwargs
)
else:
raise ValueError(f"Invalid port type: {port_type}")

return ports[port_id]

Expand All @@ -245,16 +264,23 @@ def reference_to_port(
raise ValueError("Cannot get port from reference {port_reference}")
port_reference = reference

elems = port_reference.split("/")
port_type, controller_id, fem_id, port_id = elems[-4:]

port_type = port_type[:-1]
if controller_id.isdigit():
controller_id = int(controller_id)
fem_id = int(fem_id)
port_id = int(port_id)
try:
elems = port_reference.split("/")
port_type, controller_id, fem_id, port_id = elems[-4:]

port_type = port_type[:-1]
if controller_id.isdigit():
controller_id = int(controller_id)
fem_id = int(fem_id)
port_id = int(port_id)
except Exception as e:
raise ValueError(
f"Unable to parse port reference for OPX1000 FEM: {port_reference}"
) from e

return self._get_port(controller_id, fem_id, port_id, port_type, create=create)
return self._get_port(
controller_id, fem_id, port_id, port_type, create=create
)

def get_analog_output(
self,
Expand Down
Loading