Skip to content

Commit

Permalink
Multiversion Commandtable support
Browse files Browse the repository at this point in the history
  • Loading branch information
markheik committed Aug 4, 2022
1 parent ff43d6c commit d3e895e
Show file tree
Hide file tree
Showing 7 changed files with 315 additions and 50 deletions.
19 changes: 14 additions & 5 deletions src/zhinst/toolkit/command_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,16 @@ class HeaderEntry(ParentEntry):
Args:
schema: JSON schema of the node.
path: Path representation of the node.
version: JSON schema version
"""

def __init__(self, schema: dict, path: tuple):
def __init__(self, schema: dict, path: tuple, version: t.Optional[str] = None):
super().__init__(schema, path)
self._childs["version"] = schema["properties"]["version"]["enum"][-1]
# L1 22.08 new schema format
if version:
self._childs["version"] = version
else:
self._childs["version"] = schema["properties"]["version"]["enum"][0]

@property
def version(self) -> str:
Expand Down Expand Up @@ -299,10 +304,14 @@ def table(self) -> ListEntry:
"""Table entry of the built command table."""
return self._table

def _header_entry(self):
return HeaderEntry(self._ct_schema["definitions"]["header"], ("header",))
def _header_entry(self) -> HeaderEntry:
return HeaderEntry(
self._ct_schema["definitions"]["header"],
("header",),
self._ct_schema.get("version", ""),
)

def _table_entry(self):
def _table_entry(self) -> ListEntry:
return ListEntry(self._ct_schema["definitions"]["table"], ("table",))

def clear(self) -> None:
Expand Down
4 changes: 3 additions & 1 deletion src/zhinst/toolkit/driver/nodes/command_table_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ class CommandTableNode(Node):
device_type: Device type.
"""

def __init__(self, root: NodeTree, tree: t.Tuple[str], device_type: str) -> None:
def __init__(
self, root: NodeTree, tree: t.Tuple[str, ...], device_type: str
) -> None:
Node.__init__(self, root, tree)
self._device_type = device_type

Expand Down
45 changes: 45 additions & 0 deletions tests/command_table/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import json
import pytest
from pathlib import Path

from zhinst.toolkit.command_table import CommandTable


CT_SCHEMA_22_02 = Path(__file__).parent / "data/command_table_schema_22_02.json"
CT_SCHEMA_22_08 = Path(__file__).parent / "data/command_table_schema_22_08.json"


@pytest.fixture(scope="function")
def command_table_completed():
"""L1 22.02"""
with open(Path(__file__).parent / "data/command_table_completed.json") as f:
data = json.load(f)
yield data


@pytest.fixture(scope="module")
def command_table_schema_22_02():
"""L1 22.02"""
with open(CT_SCHEMA_22_02) as f:
data = json.load(f)
return data


@pytest.fixture(scope="module")
def command_table_schema_22_08():
"""L1 22.08"""
with open(CT_SCHEMA_22_08) as f:
data = json.load(f)
return data


@pytest.fixture(scope="module", params=[CT_SCHEMA_22_02, CT_SCHEMA_22_08])
def command_table_schema(request):
with open(request.param) as f:
data = json.load(f)
return data


@pytest.fixture
def command_table(command_table_schema):
yield CommandTable(command_table_schema)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://json-schema.org/draft-04/schema#",
"header": {
"version": "1.1",
"version": "1.1.0",
"userString": "Test string"
},
"table": [
Expand Down
File renamed without changes.
218 changes: 218 additions & 0 deletions tests/command_table/data/command_table_schema_22_08.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
{
"$schema": "https://json-schema.org/draft-04/schema#",
"title": "AWG Command Table Schema",
"description": "Schema for ZI SHFSG AWG Command Table",
"version": "1.1.0",
"definitions": {
"header": {
"properties": {
"version": {
"type": "string",
"pattern": "^1\\.[0-1](\\.[0-9]+)?$",
"description": "File format version (Major.Minor / Major.Minor.Patch). This version must match with the relevant schema version."
},
"partial": {
"description": "Set to true for incremental table updates",
"type": "boolean",
"default": "false"
},
"userString": {
"description": "User-definable label",
"type": "string",
"maxLength": 30
}
},
"required": [
"version"
]
},
"table": {
"items": {
"$ref": "#/definitions/entry"
},
"minItems": 0,
"maxItems": 1024
},
"entry": {
"properties": {
"index": {
"$ref": "#/definitions/tableindex"
},
"waveform": {
"$ref": "#/definitions/waveform"
},
"phase": {
"$ref": "#/definitions/phase"
},
"amplitude00": {
"$ref": "#/definitions/amplitude"
},
"amplitude01": {
"$ref": "#/definitions/amplitude"
},
"amplitude10": {
"$ref": "#/definitions/amplitude"
},
"amplitude11": {
"$ref": "#/definitions/amplitude"
},
"oscillatorSelect": {
"$ref": "#/definitions/oscillatorselect"
}
},
"additionalProperties": false,
"required": [
"index"
]
},
"tableindex": {
"type": "integer",
"minimum": 0,
"maximum": 1023,
"exclusiveMinimum": false,
"exclusiveMaximum": false
},
"waveform": {
"properties": {
"index": {
"$ref": "#/definitions/waveformindex"
},
"length": {
"$ref": "#/definitions/waveformlength"
},
"samplingRateDivider": {
"$ref": "#/definitions/samplingratedivider"
},
"playZero": {
"$ref": "#/definitions/playzero"
},
"awgChannel0": {
"$ref": "#/definitions/awgchannel"
}
},
"additionalProperties": false,
"anyOf": [
{
"required": [
"index"
]
},
{
"required": [
"playZero",
"length"
]
}
]
},
"waveformindex": {
"description": "Index of the waveform to play as defined with the assignWaveIndex sequencer instruction",
"type": "integer",
"minimum": 0,
"maximum": 65535,
"exclusiveMinimum": false,
"exclusiveMaximum": false
},
"awgchannel": {
"description": "Assign the given AWG channel to signal output 0 & 1",
"type": "array",
"minItems": 1,
"maxItems": 2,
"uniqueItems": true,
"items": {
"type": "string",
"enum": [
"sigout0",
"sigout1"
]
}
},
"waveformlength": {
"description": "The length of the waveform in samples",
"type": "integer",
"multipleOf": 16,
"minimum": 32,
"exclusiveMinimum": false
},
"samplingratedivider": {
"descpription": "Integer exponent n of the sampling rate divider: 2.0 GSa/s / 2^n, n in range 0 ... 13",
"type": "integer",
"minimum": 0,
"maximum": 13
},
"playzero": {
"description": "Play a zero-valued waveform for specified length of waveform, equivalent to the playZero sequencer instruction",
"type": "boolean",
"default": "false"
},
"phase": {
"properties": {
"value": {
"description": "Phase value of the given sine generator in degree",
"type": "number"
},
"increment": {
"description": "Set to true for incremental phase value, or to false for absolute",
"type": "boolean",
"default": "false"
}
},
"additionalProperties": false,
"required": [
"value"
]
},
"amplitude": {
"properties": {
"value": {
"description": "Amplitude scaling factor of the given AWG channel",
"type": "number",
"minimum": -1.0,
"maximum": 1.0,
"exclusiveMinimum": false,
"exclusiveMaximum": false
},
"increment": {
"description": "Set to true for incremental amplitude value, or to false for absolute",
"type": "boolean",
"default": "false"
}
},
"additionalProperties": false,
"required": [
"value"
]
},
"oscillatorselect": {
"properties": {
"value": {
"description": "Index of oscillator that is selected for sine/cosine generation",
"type": "number",
"minimum": 0,
"maximum": 7,
"exclusiveMinimum": false,
"exclusiveMaximum": false
}
},
"additionalProperties": false,
"required": [
"value"
]
}
},
"properties": {
"$schema": {
"type": "string"
},
"header": {
"$ref": "#/definitions/header"
},
"table": {
"$ref": "#/definitions/table"
}
},
"additionalProperties": false,
"required": [
"header"
]
}
Loading

0 comments on commit d3e895e

Please sign in to comment.