CommandTable#

class CommandTable(json_schema: Union[str, dict], active_validation: bool = True)[source]#

Bases: object

Representation of a ZI device command table.

The class provides functionality to create and modify existing command tables. The CommandTable can be modified by via header and table properties.

Parameters:
  • json_schema (Union[str, dict]) – JSON Schema of the command table.

  • active_validation (bool) –

    Active validation of table entries. (default = True)

    Active validation enabled:

    Each time a table entry is accessed, the values are validated against the given JSON schema. It is suggested to keep disabled in production code as it will slow the command table creation.

    Active validation disabled:

    No validation happens during command table entry modifications, thus making the creation of the command table faster.

    Method is_valid() can be used for command table validation when active validation is disabled. It is recommended to avoid it in production code.

New in version 0.5.0: The active_validation parameter was added.

Example

>>> from zhinst.toolkit import CommandTable
>>> ct = CommandTable(json_schema)

The header and table and then be called:

>>> ct.header.version
"1.1"
>>> ct.header.userString = "My table"
>>> ct.table[0].amplitude.value = 1
>>> ct.table[0].amplitude
1
>>> ct.as_dict()

Active validation

Using active validation, error raised instantly on incorrect value:

>>> ct = CommandTable(json_schema, active_validation=True)
>>> ct.table[0].amplitude0.value = 999e9
ValidationError

Disabling active validation:

No ValidationError is raised during the creation of the command table, but once it is uploaded or called as_dict(), the validation happens.

>>> ct = CommandTable(json_schema, active_validation=False)
>>> ct.table[0].amplitude0.value = 999e9  # No errors raised
>>> ct.as_dict()
ValidationError

Disabling active validation improves the speed of large command tables:

>>> for i in range(1024):
>>>    ct.table[i].waveform.index = 1
>>>    ct.table[i].amplitude0.value = 1
>>>    ct.table[i].amplitude1.value = -0.0
>>>    ct.table[i].amplitude0.increment = False
>>>    ct.table[i].amplitude0.increment = True

Methods

as_dict()

Return a dictionary representation of the CommandTable.

clear()

Clear CommandTable back to its initial state.

is_valid([raise_for_invalid])

Checks if the command table is valid.

update(command_table)

Update the existing instance of CommandTable with command table JSON.

Attributes

active_validation

State of active validation.

header

Header of the built command table.

table

Table entry of the built command table.