Skip to content

Commit

Permalink
Switch to zhinst.comms 3.0
Browse files Browse the repository at this point in the history
This commit adapts the labone api to work with the latest zhinst.comms
version 3.0. The biggest changes are the autogenerated capnp struct stubs
and the server side parsing of the shf vectors
  • Loading branch information
tobiasah committed Sep 11, 2024
1 parent ec2c500 commit bc6c923
Show file tree
Hide file tree
Showing 30 changed files with 3,343 additions and 2,675 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# Labone Python API Changelog


## Version 3.0.0

* Enable server side parsing of the shf vectors. This is a breaking change since
the structure of the shf vector structs are now unified with the capnp schema.
* Replace the following `labone.core.Value` types with their capnp equivalent:
`ShfDemodulatorVectorData`,`ShfResultLoggerVectorData`,`ShfScopeVectorData`,
`ShfPidVectorData`,`CntSample`,`TriggerSample`
* Move the `extra_header` from the annotated value into the value field. This only affects
shf vectors
* Adapt the `session.set` and `session.set_with_expression` functions to take either
an `AnnotatedValue` or `Value` and a path. This prevents unnecessary copies.
* Add support for `zhinst.comms` 3.0
* Update the `hpk_schema` to the latest version. This included stubs for all structs
defined in the capnp schema.

## Version 2.3.2
* Pump version of `zhinst.comms` to 2.1

Expand Down
18 changes: 6 additions & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dependencies = [
"numpy>=1.20",
"packaging",
"typing_extensions>=4.8.0",
"zhinst-comms~=2.1",
"zhinst-comms>=2.0",
]

[project.urls]
Expand All @@ -54,13 +54,7 @@ packages = ["src/labone"]
python = ["3.9", "3.10", "3.11", "3.12"]

[tool.hatch.envs.test]
dependencies = [
"coverage[toml]>=6.5",
"hypothesis",
"munch==4.0.0",
"pytest",
"pytest-asyncio",
]
dependencies = ["coverage[toml]>=6.5", "hypothesis", "pytest", "pytest-asyncio"]

[tool.pytest.ini_options]
markers = [
Expand All @@ -85,11 +79,11 @@ python = ["3.9", "3.10", "3.11", "3.12"]

[tool.hatch.envs.lint]
dependencies = [
"black>=23.1.0",
"mypy>=1.0.0",
"ruff>=0.4.0",
"black>=24.8.0",
"mypy>=1.11.2",
"ruff>=0.6.4",
"numpy>=1.20",
"zhinst-comms~=2.1",
"zhinst-comms>=2.0",
]

[tool.hatch.envs.lint.scripts]
Expand Down
5 changes: 4 additions & 1 deletion src/labone/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
ListNodesInfoFlags,
Session,
)
from labone.core.shf_vector_data import ShfGeneratorWaveformVectorData
from labone.core.subscription import (
CircularDataQueue,
DataQueue,
DistinctConsecutiveDataQueue,
)
from labone.core.value import AnnotatedValue
from labone.core.value import AnnotatedValue, Value

__all__ = [
"AnnotatedValue",
Expand All @@ -35,4 +36,6 @@
"ServerInfo",
"KernelInfo",
"ZIContext",
"Value",
"ShfGeneratorWaveformVectorData",
]
26 changes: 14 additions & 12 deletions src/labone/core/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import zhinst.comms

from labone.core import hpk_schema
from labone.errors import LabOneError


Expand Down Expand Up @@ -143,27 +144,28 @@ class EmptyDisconnectedDataQueueError(StreamingError, QueueEmpty):


_ZI_ERROR_MAP = {
1: CancelledError,
3: NotFoundError,
4: OverwhelmedError,
5: BadRequestError,
6: UnimplementedError,
7: InternalError,
8: UnavailableError,
9: LabOneTimeoutError,
hpk_schema.ErrorKind.cancelled: CancelledError,
hpk_schema.ErrorKind.unknown: LabOneCoreError,
hpk_schema.ErrorKind.notFound: NotFoundError,
hpk_schema.ErrorKind.overwhelmed: OverwhelmedError,
hpk_schema.ErrorKind.badRequest: BadRequestError,
hpk_schema.ErrorKind.unimplemented: UnimplementedError,
hpk_schema.ErrorKind.internal: InternalError,
hpk_schema.ErrorKind.unavailable: UnavailableError,
hpk_schema.ErrorKind.timeout: LabOneTimeoutError,
}


def get_streaming_error(err: zhinst.comms.DynamicStruct) -> LabOneCoreError:
def raise_streaming_error(err: hpk_schema.Error) -> None:
"""Create labone error from a labone error struct.
Args:
err: The streaming error to be converted.
Returns:
The corresponding error.
Raises:
The converted error.
"""
return _ZI_ERROR_MAP.get(err.kind, LabOneCoreError)(
raise _ZI_ERROR_MAP.get(err.kind, LabOneCoreError)( # type: ignore[call-overload]
err.message,
code=err.code,
category=err.category,
Expand Down
2,963 changes: 2,119 additions & 844 deletions src/labone/core/hpk_schema.py

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion src/labone/core/kernel_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from dataclasses import dataclass

import zhinst.comms
from packaging import version
from typing_extensions import TypeAlias

from labone.core import hpk_schema
Expand Down Expand Up @@ -83,8 +84,13 @@ def __init__(
*,
context: ZIContext,
server_info: ServerInfo,
capability_version: version.Version,
) -> None:
super().__init__(core_session, context=context)
super().__init__(
core_session,
context=context,
capability_version=capability_version,
)
self._server_info = server_info

@staticmethod
Expand Down Expand Up @@ -127,10 +133,14 @@ async def create(
kernel_info,
schema=hpk_schema.get_schema_loader().get_interface_schema(HPK_SCHEMA_ID),
)
compatibility_version = version.Version(
(await core_session.getSessionVersion()).version,
)
return KernelSession(
core_session,
context=context,
server_info=server_info,
capability_version=compatibility_version,
)

@property
Expand Down
Loading

0 comments on commit bc6c923

Please sign in to comment.