Variables
An array of variables. |
|
A slice of an |
|
A class for lazy evaluation of the maximum of variable quantities. |
|
A class for scalar quantities whose values are unknown or can be changed. |
|
A single element of an |
|
alias of |
|
An abstract base class for quantities whose values can be changed. |
|
A set of |
|
An enum specifying the supported variable units. |
The following data types can be used to define slices:
- keysight.qcs.variables.SliceLike
alias of
Union
[int
,slice
,List
[int
]]
Array
- class keysight.qcs.variables.Array(name: str, *, value: None | ArrayLike = None, shape: None | int | Iterable[int] = None, dtype: type | None = None, unit: str | UnitsEnum | None = None, read_only: bool = False)
An array of variables.
import keysight.qcs as qcs # initialize an array by specifying its shape array1 = qcs.Array("my_array1", shape=(2, 2)) # initialize an array by providing a value array2 = qcs.Array("my_array1", value=[[0, 0], [0, 0]])
- Parameters:
name – The name of this array.
value – The value of this array.
shape – The shape of this array. If
None
, it is deduced from the shape ofvalue
.dtype – The data type of the variables in this array. If
None
, defaults to the coerced type, seeDTYPE_COERCIONS
.unit – The unit of the array, which must be one of
UnitsEnum
. Defaults to None.read_only – Wether this array is read-only or not.
- Raises:
ValueError – If both
shape
andvalue
are specified.ValueError – If neither
shape
orvalue
are specified.ValueError – If an empty
shape
is specified.ValueError – If the
unit
is not one ofUnitsEnum
.
- property ndim: int
The number of dimensions of this array.
import keysight.qcs as qcs array = qcs.Array("my_array", shape=(2, 3)) assert array.ndim == 2
- property size: int | None
The total number of elements in this array.
import keysight.qcs as qcs array = qcs.Array("my_array", shape=(2, 3)) assert array.size == 6
- property shape: tuple[int, ...]
The shape of this array.
import keysight.qcs as qcs array = qcs.Array("my_array", shape=(1, 9)) assert array.shape == (1, 9)
- property value: None | numpy.ndarray
The value of this array.
import keysight.qcs as qcs array = qcs.Array("my_array", value=[[0, 0], [0, 0]]) assert (array.value == [[0, 0], [0, 0]]).all()
- set_zero() None
Set all elements of the array to zero.
import keysight.qcs as qcs array = qcs.Array("my_array", value=[[1, 2], [3, 4]]) array.set_zero() assert (array.value == [[0, 0], [0, 0]]).all()
ArraySlice
- class keysight.qcs.variables.ArraySlice(name: str, *, value: None | ArrayLike = None, shape: None | int | Iterable[int] = None, dtype: type | None = None, unit: str | UnitsEnum | None = None, read_only: bool = False)
A slice of an
Array
.Note
Instances of this class are automatically created when getting slices of an
Array
and should not need to be directly created.import keysight.qcs as qcs # initialize array to slice array = qcs.Array("my_array", value=[[1, 2], [3, 4]]) # slice the first row assert (array[0].value == [1, 2]).all() # slice to get individual entries assert array[0, 0].value == 1 assert array[1, 0].value == 3When an ArraySlice has another ArraySlice as a parent, the original ancestor is inherited as
parent
. Theslicer
specifies how to slice the original ancestor to get this instance of an ArraySlice.
- Parameters:
parent – The array to slice from.
slices – The slices to take from the parent array.
- property idx: tuple[int, ...]
The indices of this in its parent.
Max
Scalar
- class keysight.qcs.variables.Scalar(name: str, value: SUPPORTED_DTYPES | None = None, dtype: type | None = None, unit: str | UnitsEnum | None = None, read_only: bool = False)
A class for scalar quantities whose values are unknown or can be changed.
import keysight.qcs as qcs # initialize a scalar with no set value scalar = qcs.Scalar("my_scalar", dtype=float) # initialize a scalar with set value scalar = qcs.Scalar("my_scalar", value=0.1, dtype=float)
- Parameters:
name – The name of scalar.
value – The value of scalar, or
None
for a scalar with no set value.dtype – The dtype of scalar, which must be one of
DTYPE_COERCIONS
. Defaults tocomplex
as it is the broadest supported type.unit – The unit of the scalar, which must be one of
UnitsEnum
. Defaults to None.read_only – Whether the scalar is read-only.
- Raises:
ValueError – If
dtype
is not one ofDTYPE_COERCIONS
.ValueError – If the
unit
is not one ofUnitsEnum
.
- property value: None | SUPPORTED_DTYPES
The value of this variable.
ScalarRef
- class keysight.qcs.variables.ScalarRef(name: str, value: SUPPORTED_DTYPES | None = None, dtype: type | None = None, unit: str | UnitsEnum | None = None, read_only: bool = False)
A single element of an
Array
.Note
Instances of this class are automatically created when getting slices of an
Array
and should not need to be directly created.import keysight.qcs as qcs # initialize an array array = qcs.Array("my_array", value=[[0, 1], [2, 3]]) # slice the array to obtain the element with indices (0, 0) scalar_ref = array[0, 0] assert scalar_ref.value == 0 assert scalar_ref.name == array.name assert scalar_ref.dtype == array.dtype
- Parameters:
parent – The array to obtain the element from.
idx – The index of the element in the parent array.
- property idx: tuple[int, ...]
The indices of this in its parent.
Variable
- class keysight.qcs.variables.Variable
An abstract base class for quantities whose values can be changed.
- property constant: bool
Whether the variable is constant.
- property dtype: type
The type of this variable.
- property name: str
The name of this variable.
- property read_only: bool
Whether the variable is read-only.
- abstract property value
The value of this variable.