Graphs¶
Boulder Opal uses graphs to represent all computations. All usage of graphs is via the
Graph
object, which you can construct directly or using the
qctrl.Qctrl.create_graph()
method.
This page documents the available graph operations, together with the auxiliary features in the graphs module, namely the graph object itself and the classes representing the types of possible graph nodes. To learn more about the role of graphs and their usage in Boulder Opal see the How to calculate with graphs User guide.
Warning
Note that the methods on the graph object can also be accessed via the Qctrl.operations
namespace, but that usage is deprecated and will be removed soon. To migrate, change code of the
form:
with qctrl.create_graph() as graph:
# Lines involving `qctrl.operations`, for example:
x = qctrl.operations.multiply(2, 3)
into:
graph = qctrl.create_graph()
# Lines involving `graph`, for example:
x = graph.multiply(2, 3)
Graph object¶
The graph object is the main entrypoint to the QCTRL graph ecosystem.
Utility class for representing and building a QCTRL data flow graph. 
Data types¶
Each graph operation creates a node, and each node has a type corresponding to the type of the data it produces.
A kernel to be used in a convolution. 

A piecewiseconstant tensorvalued function of time (or batch of such functions). 

A piecewiseconstant sparsematrixvalued function of time. 

A sampleable tensorvalued function of time (or batch of such functions). 

A target gate for an infidelity calculation. 

A multidimensional array of data. 
Optimization variables¶
When performing optimizations, you can use these operations to create the optimizable variables that can be tuned by the optimizer in order to minimize your cost function.
Creates a sequence of variables with an anchored difference bound. 

Creates optimization variables, which can be bounded, semibounded, or unbounded. 

Creates a piecewiseconstant signal constructed from Fourier components. 

Creates a real sampleable signal constructed from Fourier components. 
Building Hamiltonians¶
You can use these operations to build graphs representing Hamiltonians. Hamiltonians are represented as tensorvalued functions of time. Tensorvalued functions of time can be either piecewiseconstant (PWCs) or smooth (STFs, which stands for sampleable tensor functions). You can manipulate PWCs and STFs either by using the operations in this section or by applying most mathematical functions. You can also convert PWCs into STFs by applying linear filters, and can convert STFs into PWCs by discretizing.
Working with piecewiseconstant tensor functions (PWCs)¶
Creates a complex piecewiseconstant signal from moduli and phases. 

Creates a piecewiseconstant function of time that is constant over a specified duration. 

Creates a constant piecewiseconstant operator over a specified duration. 

Creates a piecewiseconstant function of time. 

Creates a constant operator multiplied by a piecewiseconstant signal. 

Creates the Hermitian part of a piecewiseconstant operator. 

Creates a piecewiseconstant signal (scalarvalued function of time). 

Creates the sum of multiple piecewiseconstant terms. 

Creates a piecewiseconstant signal constructed from Fourier components. 

Samples a Pwc at the given times. 

Creates the symmetrization of a piecewiseconstant function. 
Working with sampleable tensor functions (STFs)¶
You can use these functions to create and manipulate STFs. Note that a powerful way to create analytic STFs is to start with identity_stf
and then apply a sequence of mathematical functions.
Create a constant sampleable tensorvalued function of time. 

Creates a constant operator. 

Returns an Stf representing the identity function, f(t) = t. 

Samples the onesided power spectral density (PSD) of a random noise process in the time domain and returns the resultant noise trajectories as an Stf. 

Creates a real sampleable signal constructed from Fourier components. 

Samples an Stf at the given times. 

Creates a constant operator multiplied by a sampleable signal. 

Creates the Hermitian part of an operatorvalued sampleable function. 

Creates the sum of multiple sampleable functions. 
Filtering and discretizing¶
Creates the convolution of a piecewiseconstant function with a kernel. 

Creates a piecewiseconstant function by discretizing a sampleable function. 

Creates a convolution kernel representing a normalized Gaussian. 

Creates a convolution kernel representing the sinc function. 
Time evolution¶
You can use these operations to calculate the time evolution of your open or closed quantum system, either for simulations or optimizations.
Calculates the state evolution of an open system described by the GKS–Lindblad master equation. 

Calculates an appropriate Krylov subspace dimension (\(k\)) to use in the Lanczos integrator while keeping the total error in the evolution below a given error tolerance. 

Obtains the range of the eigenvalues of a Hermitian operator. 

Calculates the time evolution of a state generated by a piecewiseconstant Hamiltonian by using the Lanczos method. 

Calculates the unitary timeevolution operators for a system defined by a piecewiseconstant Hamiltonian. 

Calculates the timeevolution operators for a system defined by an STF Hamiltonian by using a 4th order Runge–Kutta method. 
Optimal and robust control¶
You can use these operations, together with the operations for creating optimization variables and Hamiltonians, to define convenient cost functions for optimal and robust control.
Creates the total infidelity of the given piecewiseconstant system. 

Creates the total infidelity of a given system with a sampleable Hamiltonian. 

Creates information about the target for system time evolution. 
Large systems¶
You can use these operations, together with those for building Hamiltonians, to build graphs that efficiently handle large quantum systems.
Creates a constant sparse piecewiseconstant operator over a specified duration. 

Calculates the state evolution of an open system described by the GKS–Lindblad master equation. 

Calculates an appropriate Krylov subspace dimension (\(k\)) to use in the Lanczos integrator while keeping the total error in the evolution below a given error tolerance. 

Creates the Hermitian part of a piecewiseconstant operator. 

Creates a sparse piecewiseconstant operator (sparsematrixvalued function of time). 

Creates the sum of multiple sparsematrixvalued piecewiseconstant functions. 

Obtains the range of the eigenvalues of a Hermitian operator. 

Calculates the time evolution of a state generated by a piecewiseconstant Hamiltonian by using the Lanczos method. 
Mølmer–Sørensen gates¶
You can use these operations to efficiently model systems described by Mølmer–Sørensen interactions.
Calculates the cost for robust optimization of a Mølmer–Sørensen gate. 

Calculates the displacements for each mode and ion combination where ions are described by a Mølmer–Sørensentype interaction. 

Calculates the final operational infidelity of the Mølmer–Sørensen gate. 

Calculates the relative phases for all pairs of ions described by a Mølmer–Sørensentype interaction. 
Random operations¶
You can use these operations to create random quantities, which take different values each time they are evaluated. These operations are most useful in simulations and stochastic optimizations.
Creates random samples from the data that you provide. 

Samples the onesided power spectral density (PSD) of a random noise process in the time domain and returns the resultant noise trajectories as an Stf. 

Creates a sample of normally distributed random numbers. 

Creates a sample of uniformly distributed random numbers. 
Manipulating tensors¶
You can use these operations to manipulate the structures of tensors.
Concatenates a list of tensors along a specified dimension. 

Calculates the cumulative sum of a tensor along a specified dimension. 

Performs tensor contraction via Einstein summation convention. 

Repeats elements of a tensor. 

Reverses a tensor along some specified dimensions. 

Returns the sum of all the elements in a tensor (or a list of tensors with the same shape), or the sum of a tensor along one or multiple axes. 

Creates a real or complex Tensor with the data provided. 

Returns the input tensor with its dimensions reordered. 
Mathematical functions¶
You can use these operations to perform standard mathematical computations.
Arithmetic¶
Calculates the elementwise sum between numbers, np.ndarrays, Tensors, Pwcs, or Stfs. 

Calculates the cumulative sum of a tensor along a specified dimension. 

Calculates the elementwise roundeddown division between numbers, np.ndarrays, Tensors, Pwcs, or Stfs. 

Calculates the elementwise product between numbers, np.ndarrays, Tensors, Pwcs, or Stfs. 

Returns the elementwise numerical negative value of an object. 

Calculates the elementwise power between numbers, np.ndarrays, Tensors, Pwcs, or Stfs. 

Calculates the elementwise difference between numbers, np.ndarrays, Tensors, Pwcs, or Stfs. 

Returns the sum of all the elements in a tensor (or a list of tensors with the same shape), or the sum of a tensor along one or multiple axes. 

Calculates the elementwise division between numbers, np.ndarrays, Tensors, Pwcs, or Stfs. 
Linear algebra¶
Returns the elementwise adjoint of the last two dimensions of an object. 

Performs tensor contraction via Einstein summation convention. 

Calculates the Kronecker product between np.ndarrays, Tensors, Pwcs, or Stfs. 

Calculates the matrix multiplication between np.ndarrays, Tensors, Pwcs, or Stfs. 

Returns the elementwise trace of an object. 

Returns the input tensor with its dimensions reordered. 
Basic functions¶
Returns the elementwise absolute value of an object. 

Returns the elementwise exponential of an object. 

Returns the elementwise natural logarithm of an object. 

Returns the elementwise square root of an object. 
Trigonometric functions¶
Returns the elementwise arccosine of an object. 

Returns the elementwise arcsine of an object. 

Returns the elementwise arctangent of an object. 

Returns the elementwise cosine of an object. 

Returns the elementwise sine of an object. 

Returns the elementwise tangent of an object. 
Hyperbolic functions¶
Returns the elementwise hyperbolic cosine of an object. 

Returns the elementwise hyperbolic sine of an object. 

Returns the elementwise hyperbolic tangent of an object. 
Handling complex numbers¶
Returns the elementwise absolute value of an object. 

Returns the elementwise argument of an object. 

Creates elementwise complex values from real numbers, np.ndarrays, Tensors, Pwcs, or Stfs, that is, the real and imaginary parts. 

Returns the elementwise complex conjugate of an object. 

Returns the elementwise imaginary part of an object. 

Returns the elementwise real part of an object. 
Derivatives¶
Calculates a single gradient vector for all the variables. 

Calculates a single Hessian matrix for all the variables. 
Other operations¶
You typically do not need to use these operations directly.
Gets an attribute from a node value. 

Gets an item (or items) from a node value. 
Deprecated operations¶
These operations are deprecated and will be removed in the future.
This node will be removed in the future. 

This node will be removed in the future. 