Variables

keysight.qcs.variables.Array

An array of variables.

keysight.qcs.variables.ArraySlice

A slice of an Array.

keysight.qcs.variables.Max

A class for lazy evaluation of the maximum of variable quantities.

keysight.qcs.variables.Scalar

A class for scalar quantities whose values are unknown or can be changed.

keysight.qcs.variables.ScalarRef

A single element of an Array.

keysight.qcs.variables.SliceLike

alias of Union[int, slice, List[int]]

keysight.qcs.variables.Variable

An abstract base class for quantities whose values can be changed.

keysight.qcs.variables.VariableSet

A set of Variables, where individual variables can be marked as inputs and/or outputs.

keysight.qcs.variables.UnitsEnum

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 of value.

  • dtype – The data type of the variables in this array. If None, defaults to the coerced type, see DTYPE_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 and value are specified.

  • ValueError – If neither shape or value are specified.

  • ValueError – If an empty shape is specified.

  • ValueError – If the unit is not one of UnitsEnum.

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 | np.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 == 3

When an ArraySlice has another ArraySlice as a parent, the original ancestor is inherited as parent. The slicer 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.

property parent: Variable

The parent that this is an element of.

Max

class keysight.qcs.variables.Max(*args: float | Iterable[float] | Variable[float])

A class for lazy evaluation of the maximum of variable quantities.

Parameters:

*args – The variables to take the maximum of.

Raises:

ValueError – If the dtype is complex.

property variables: list[Variable[float]]

The variables whose values are to be compared.

simplify() Scalar[float]

Simplify this maximum by evaluating the maxima of any constants.

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 to complex 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:
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.

property parent: Variable

The parent that this is an element of.

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 parents: Generator[Variable]

Yield the root variables that determine the value of this.

property read_only: bool

Whether the variable is read-only.

property unit: UnitsEnum

The unit of the variable.

abstract property value

The value of this variable.

keysight.qcs.variables.get_value(val: any | Variable) any

Returns a value either by pass-through or getting the value of a variable.

Parameters:

val – is the object to either pass through or to return the value attribute of.

class keysight.qcs.variables.UnitsEnum

An enum specifying the supported variable units.

The names (values) are: none (0) s (1) Hz (2) rad (3)

from_string() str

Construct a <class ‘Keysight.Qcs.SharedTypes.Variables.UnitsEnum’> from a string.

VariableSet

class keysight.qcs.variables.VariableSet

A set of Variables, where individual variables can be marked as inputs and/or outputs.

property variables: Generator[Variable]

Yields the variables from this.

declare(val: Variable) Variable

Adds a variable to this.

Parameters:

val – The variable to add.

remove(name: str) None

Removes a variable from this.

Parameters:

name – The variable name to remove.

On this page