quairkit.ansatz.container

The source file of the Sequential class.

class quairkit.ansatz.container.OperatorList(*operators)

Sequential container.

Parameters:
operators : Operator

initial operators ready to be a sequential

Note

Sublayers will be added to this container in the order of argument in the constructor. The argument passed to the constructor can be iterable Layers or iterable name Layer pairs.

append(op)

Appends an given operator to the end.

Parameters:
op : Operator

module to append

extend(sequential)

Appends an given operator to the end.

Parameters:
sequential : OperatorList

module to append

property oper_history : list[dict[str, str | list[int] | Tensor]]

Return the operator history of this Sequential

property param : Tensor

Flattened parameters in this list.

property grad : ndarray

Gradients with respect to the flattened parameters.

update_param(theta, idx=None)

Replace parameters of all/one layer(s) by theta.

Parameters:
theta : Tensor | ndarray | float

New parameters

idx : int | None

Index of replacement. Defaults to None, referring to all layers.

transfer_static()

set stop_gradient of all parameters of the list as True

randomize_param(arg0=0, arg1=6.283185307179586, method='Uniform')

Randomize parameters of the list based on the initializer. Current we only support Uniform and Normal initializer.

Parameters:
arg0 : float

first argument of the initializer. Defaults to 0.

arg1 : float

first argument of the initializer. Defaults to 2 pi.

method : str

The sampling method. Defaults to ‘Uniform’.