cuTensorNet
cuTensorNet.jl wraps NVIDIA's cuTensorNet library, part of cuQuantum, for contracting and decomposing tensor networks and simulating quantum circuits. It has no integration with Base or LinearAlgebra functions; it offers two levels:
- The functions and types documented below wrap cuTensorNet's routines and objects. They fall into three groups:
- Network contractions: build a
CuNetworkfrom input tensors, find a contraction path withrehearse_contraction, and contract it withcontract!, optionally computing gradients withcompute_gradients!. - Tensor decompositions:
tensor_qr!,tensor_svd!andgate_split!, onCuArrays with mode labels or on cuTENSOR'sCuTensors. - States: build a
CuNetworkStateby applying operators to it, then compute the state, its amplitudes, expectation values, marginals or samples, or project it on an MPS.
- Network contractions: build a
- The generated bindings in
libcutensornet.jlfollow NVIDIA's C API, and change with the cuQuantum release. Use them together withhandle.
The wrappers use snake-case names, and share these conventions:
- Modes are labeled with integers (or, for the decompositions, characters). Modes with the same label are contracted. The modes of a state are numbered from 0, as in NVIDIA's API.
- Objects keep the arrays they are given alive, and the library uses their memory directly: change their contents only where a function says that is supported.
- Settings that NVIDIA exposes as attributes are passed as keyword structs (
OptimizerConfig,SVDConfig,NetworkAutotunePreferences), or withattribute!andconfigure!, which take NVIDIA's attribute enums and values of the type NVIDIA documents for them. The same goes for the enum-typed keywords of the wrappers, such asalgoofgate_split!. - Functions that launch work take a
streamkeyword, which defaults to the task's stream. The computations on states wait for their result; the others don't.
CuTensorNetwork, perform_contraction!, AutoTune, NoAutoTune and AutotunePreferences wrap NVIDIA's deprecated network descriptors and contraction plans, and are deprecated in favor of CuNetwork.
Public
cuTensorNet.CUTENSORNETError — Type
CUTENSORNETError(code::cutensornetStatus_t)The exception thrown when a cuTensorNet call fails, with the status code it returned.
cuTensorNet.CuNetwork — Type
CuNetwork{T}()An empty tensor network with elements of type T, to be contracted on the GPU. Add input tensors with append_tensor! and the output tensor with set_output!. Then find a contraction path with rehearse_contraction (or reuse one with set_optimizer_info!), allocate the workspace with prepare_contraction!, and contract the network with contract! as often as needed. The network keeps its tensors alive and uses their memory directly: their contents can change between contractions, but call purge_cache! when that of a constant input does.
net = CuNetwork{Float64}()append_tensor!(net, A, [1, 2]) # C[i,k] = A[i,j] B[j,k]append_tensor!(net, B, [2, 3])set_output!(net, C, [1, 3])rehearse_contraction(net, 2^30)prepare_contraction!(net)contract!(net)Wraps cutensornetNetworkDescriptor_t, as created by cutensornetCreateNetwork.
cuTensorNet.CuNetworkOperator — Type
CuNetworkOperator{T}(extents)An operator on a state with modes of the given extents, as a sum of terms that are added with append_product! and append_mpo!. Apply it to a CuNetworkState with apply!, or compute its expectation value with CuStateExpectation.
The tensors of an operator have the state modes they act on as their first modes, in order, followed by the corresponding dual modes. This differs from the layout of the operators that apply! takes.
Wraps cutensornetNetworkOperator_t.
cuTensorNet.CuNetworkState — Type
CuNetworkState{T}(extents; purity=CUTENSORNET_STATE_PURITY_PURE)A quantum state, or other tensor network state, of modes with the given extents, starting as the vacuum state (all modes 0). Apply operators to it with apply! and the other apply_*! functions, or start from an MPS with initialize_mps!. Then compute the state itself with prepare! and compute!, or properties of it with CuStateAccessor, CuStateExpectation, CuStateMarginal, CuStateSampler and CuStateProjectionMPS. With purity = CUTENSORNET_STATE_PURITY_MIXED, it is a density matrix.
State modes are numbered from 0. The state keeps what it is given alive, but uses the memory of operators directly: register changes to an operator with update!. That memory must be device memory.
Wraps cutensornetState_t.
cuTensorNet.CuStateAccessor — Method
CuStateAccessor(state::CuNetworkState, projected_modes=Int32[])A computation of amplitudes of the state, for the projected_modes having values that are given to compute!. The amplitudes have the remaining modes in order; for a mixed state, these are the modes of the density matrix, with the dual modes numbered after the others. Prepare it with prepare!.
Wraps cutensornetCreateAccessor.
cuTensorNet.CuStateExpectation — Method
CuStateExpectation(state::CuNetworkState{T}, operator::CuNetworkOperator{T})A computation of the expectation value of operator on the state, by compute! or, with gradients, compute_with_gradients!. Prepare it with prepare!.
Wraps cutensornetCreateExpectation.
cuTensorNet.CuStateMarginal — Method
CuStateMarginal(state::CuNetworkState, modes; projected_modes=Int32[], diagonal=false)A computation of the reduced density matrix of the state on modes. With diagonal = true, only its diagonal is computed, i.e. the probabilities of the basis states. The projected_modes take the values given to compute!. Prepare it with prepare!.
Wraps cutensornetCreateMarginal and cutensornetCreateMarginalDiagonal.
cuTensorNet.CuStateProjectionMPS — Method
CuStateProjectionMPS(state::CuNetworkState{T}, dual_tensors::Vector{<:CuArray{T}},
envs::Vector{<:Pair}; coefficient=1, symmetric=false, ortho=nothing,
boundary_condition=CUTENSORNET_BOUNDARY_CONDITION_OPEN)A projection of the state on the MPS with the given dual tensors, for example to compress it or to optimize the MPS site by site. Each environment is given as lower => upper, the sites left and right of the MPS tensors it excludes, where -1 and length(dual_tensors) are the boundaries; it cannot span the whole MPS. ortho gives the orthogonality center of the MPS, if it has one, in the same form: 0 => 2 for site 1. Prepare it with prepare!, then use tensor_info, compute_env!, extract_tensor! and insert_tensor!.
Wraps cutensornetCreateStateProjectionMPS.
cuTensorNet.CuStateSampler — Method
CuStateSampler(state::CuNetworkState, modes)A sampler of the values of modes in the state, for sample!. Prepare it with prepare!.
Wraps cutensornetCreateSampler.
cuTensorNet.CuTensorNetworkContractionOptimizerInfo — Type
CuTensorNetworkContractionOptimizerInfo(net::CuNetwork)
CuTensorNetworkContractionOptimizerInfo(net::CuNetwork, data::Vector{UInt8})The contraction path of a network, with its slicing, as found by rehearse_contraction. The first form creates an empty one for net, to be filled with unpack! or attribute!; the second one recreates a path saved with pack, for a network with the same shape. Attach it to a network with set_optimizer_info!.
Query it with num_slices, num_sliced_modes and flop_count.
Wraps cutensornetContractionOptimizerInfo_t.
cuTensorNet.CuTensorNetworkSliceGroup — Type
CuTensorNetworkSliceGroup(start, stop, step)
CuTensorNetworkSliceGroup(ids::Vector{Int64})A set of slices of a sliced contraction, given as the range from start up to but not including stop, or as a list of slice ids. Slice ids are 0-based and less than num_slices. Pass it to contract! or compute_gradients! to compute part of a contraction.
Wraps cutensornetSliceGroup_t.
cuTensorNet.CuTensorSVDInfo — Type
CuTensorSVDInfo()Information about a truncated SVD, returned by tensor_svd! and gate_split!. Query it with full_extent, reduced_extent and discarded_weight.
Wraps cutensornetTensorSVDInfo_t.
cuTensorNet.NetworkAutotunePreferences — Type
NetworkAutotunePreferences(; max_iterations=3, intermediate_modes=2)Settings for autotune!. max_iterations is the number of iterations to time the candidate kernels for, and intermediate_modes whether to also tune the mode order of intermediate tensors (0 off, 1 on, 2 lets cuTensorNet decide).
cuTensorNet.OptimizerConfig — Type
OptimizerConfig(; num_graph_partitions=8, graph_cutoff_size=8, ..., seed=0, ...)Settings for the search for a contraction path by rehearse_contraction. Each keyword sets the CUTENSORNET_CONTRACTION_OPTIMIZER_CONFIG_* attribute with the corresponding name (e.g. graph_num_cuts sets GRAPH_NUM_CUTS, and num_graph_partitions GRAPH_NUM_PARTITIONS); see NVIDIA's documentation of these attributes. The defaults are those of the struct, which differ from NVIDIA's for some keywords, such as slicer_slice_factor and hyper_num_threads. hyper_num_samples > 0 makes the search try several paths, and seed makes it reproducible.
cuTensorNet.SVDConfig — Type
SVDConfig(; abs_cutoff=0.0, rel_cutoff=0.0,
s_normalization=CUTENSORNET_TENSOR_SVD_NORMALIZATION_NONE,
s_partition=CUTENSORNET_TENSOR_SVD_PARTITION_NONE)Settings for the truncated SVD of tensor_svd! and gate_split!. Singular values below abs_cutoff, or below rel_cutoff times the largest one, are discarded. s_normalization (a cutensornetTensorSVDNormalization_t) normalizes the singular values that are kept, and s_partition (a cutensornetTensorSVDPartition_t) absorbs them into U, V or both.
cuTensorNet.append_mpo! — Method
append_mpo!(op::CuNetworkOperator{T}, coefficient, modes::Vector{<:Integer},
tensors::Vector{<:CuArray{T}}; boundary_condition=CUTENSORNET_BOUNDARY_CONDITION_OPEN)
-> Int64Add a term to the operator: coefficient times a matrix product operator acting on the (0-based) state modes, with one tensor per mode. Each tensor has the modes (left bond, state mode, right bond, dual state mode), without the outer bonds at the boundaries of an open chain. Returns the id of the term.
Wraps cutensornetNetworkOperatorAppendMPO.
cuTensorNet.append_product! — Method
append_product!(op::CuNetworkOperator{T}, coefficient, modes::Vector{<:Vector{<:Integer}},
tensors::Vector{<:CuArray{T}}) -> Int64Add a term to the operator: coefficient times the product of tensors, each acting on the (0-based) state modes in the corresponding element of modes. Returns the id of the term.
Wraps cutensornetNetworkOperatorAppendProduct.
cuTensorNet.append_tensor! — Method
append_tensor!(net::CuNetwork{T}, tensor::CuArray{T}, modes;
conjugate=false, constant=false, requires_gradient=false) -> Int64Add tensor as an input of the network, with an integer label for each of its modes, and return the id the network gives it. Modes with the same label are contracted. conjugate uses the complex conjugate of the tensor, constant promises that its contents don't change between contractions so that intermediate results can be cached, and requires_gradient makes compute_gradients! compute the gradient with respect to it.
Wraps cutensornetNetworkAppendTensor.
cuTensorNet.apply! — Method
apply!(state::CuNetworkState{T}, modes, operator::CuArray{T};
immutable=true, adjoint=false, unitary=false) -> Int64
apply!(state::CuNetworkState{T}, operator::CuNetworkOperator{T}; ...) -> Int64Apply an operator to the state, and return its id. A tensor operator acts on the 0-based state modes, and has twice as many dimensions: its elements are stored following the rows of its textbook definition, i.e. as reshape(permutedims(M), ...) of a matrix M. immutable = false allows changing it later with update!, adjoint applies its adjoint instead, and unitary promises that it is unitary, which saves work.
Wraps cutensornetStateApplyTensorOperator and cutensornetStateApplyNetworkOperator.
cuTensorNet.apply_controlled! — Method
apply_controlled!(state::CuNetworkState{T}, control_modes, target_modes, operator::CuArray{T};
control_values=nothing, immutable=true, adjoint=false, unitary=false)
-> Int64Apply operator to the target_modes of the state when the control_modes have the control_values, which default to the last basis state of each mode (1 for qubits), and return its id. operator only covers the target modes, laid out as for apply!.
Wraps cutensornetStateApplyControlledTensorOperator.
cuTensorNet.apply_diagonal! — Method
apply_diagonal!(state::CuNetworkState{T}, modes, diagonal::CuArray{T};
immutable=true, adjoint=false, unitary=false) -> Int64Apply a diagonal operator to the state, given by its diagonal as a tensor with one dimension per mode, and return its id. Afterwards, compute! can't compute the full state anymore, only properties of it.
Wraps cutensornetStateApplyDiagonalTensorOperator.
cuTensorNet.apply_general_channel! — Method
apply_general_channel!(state::CuNetworkState{T}, modes, operators::Vector{<:CuArray{T}})
-> Int64Apply a general channel to the state, given by its Kraus operators, laid out as for apply!. Returns its id.
Wraps cutensornetStateApplyGeneralChannel.
cuTensorNet.apply_unitary_channel! — Method
apply_unitary_channel!(state::CuNetworkState{T}, modes, operators::Vector{<:CuArray{T}},
probabilities) -> Int64Apply a unitary channel to the state: each of operators, laid out as for apply!, with the corresponding probability. Returns its id.
Wraps cutensornetStateApplyUnitaryChannel.
cuTensorNet.apply_with_gradient! — Method
apply_with_gradient!(state::CuNetworkState{T}, modes, operator::CuArray{T},
gradient::CuArray{T}; immutable=true, adjoint=false, unitary=false)
-> Int64Apply an operator to the state as apply! does, and have compute_with_gradients! on an expectation value of the state write the gradient with respect to the operator to gradient.
Wraps cutensornetStateApplyTensorOperatorWithGradient.
cuTensorNet.attribute! — Method
attribute!(net::CuNetwork, attr::cutensornetNetworkAttributes_t, value) -> net
attribute!(info::CuTensorNetworkContractionOptimizerInfo,
attr::cutensornetContractionOptimizerInfoAttributes_t, value) -> infoSet an attribute of a network or of a contraction path, given by NVIDIA's attribute enum. value must have the type that NVIDIA documents for the attribute, e.g. attribute!(net, CUTENSORNET_NETWORK_COMPUTE_TYPE, CUTENSORNET_COMPUTE_64F). A changed contraction path must be attached again with set_optimizer_info!.
Wraps cutensornetNetworkSetAttribute and cutensornetContractionOptimizerInfoSetAttribute.
cuTensorNet.attribute — Method
attribute(net::CuNetwork, attr::cutensornetNetworkAttributes_t, R) -> RRead an attribute of a network, given by NVIDIA's attribute enum (e.g. CUTENSORNET_NETWORK_COMPUTE_TYPE), as a value of type R, the type that NVIDIA documents for the attribute. This only works for attributes with a scalar value: use tensor_ids for the lists of input tensors.
Wraps cutensornetNetworkGetAttribute.
cuTensorNet.autotune! — Method
autotune!(net::CuNetwork; prefs=NetworkAutotunePreferences(), stream=stream()) -> netTime the kernels for each pairwise contraction of the prepared network on its tensors, and use the fastest ones in later contractions. See NetworkAutotunePreferences.
Wraps cutensornetNetworkAutotuneContraction.
cuTensorNet.capture_mps! — Method
capture_mps!(state::CuNetworkState) -> stateReplace the state by the last MPS computed by compute!, dropping the operators applied so far.
Wraps cutensornetStateCaptureMPS.
cuTensorNet.compute! — Method
compute!(state::CuNetworkState; stream=stream()) -> (; tensors, extents, strides)
compute!(acc::CuStateAccessor, projected_values=[]; stream=stream()) -> amplitudes, norm
compute!(x::CuStateExpectation; stream=stream()) -> value, norm
compute!(x::CuStateMarginal, projected_values=[]; stream=stream()) -> marginalCompute a prepared state, or a property of it, and wait for the result.
- For a state, the result is the tensor of the full state, or the tensors of its MPS after
finalize_mps!. MPS tensors can be truncated: the returned extents and strides say which part of each tensor holds the data. The full state can't be computed afterapply_diagonal!. WrapscutensornetStateCompute. - For an accessor, the amplitudes of the modes that are not projected, for the projected modes having the given values, and the squared norm of the state. Wraps
cutensornetAccessorCompute. - For an expectation value, the expectation value of the operator, not divided by the squared norm of the state, which is also returned. Wraps
cutensornetExpectationCompute. - For a marginal, the reduced density matrix of its modes (or its diagonal), for the projected modes having the given values. Wraps
cutensornetMarginalCompute.
cuTensorNet.compute_env! — Method
compute_env!(x::CuStateProjectionMPS{T}, env::Pair, input, output::CuArray{T};
apply_inv_metric=false, re_resolve_channels=false, stream=stream()) -> outputCompute the environment env of the projection into output, contracted with the MPS tensor input if it isn't nothing.
Wraps cutensornetStateProjectionMPSComputeTensorEnv.
cuTensorNet.compute_gradients! — Method
compute_gradients!(net::CuNetwork; accumulate=false, slices=nothing, stream=stream())
-> Dict{Int64,CuArray}Compute the gradients of the contraction with respect to the inputs added with requires_gradient = true, after a call to contract!. They are written to the arrays set with set_gradient!, for the adjoint set with set_adjoint!, and returned by input id. The network must have been prepared with gradients = true.
Wraps cutensornetNetworkComputeGradientsBackward.
cuTensorNet.compute_with_gradients! — Method
compute_with_gradients!(x::CuStateExpectation; expectation_adjoint=1, norm_adjoint=0,
accumulate=false, stream=stream()) -> value, normCompute the expectation value as compute! does, and write the gradients with respect to the operators applied with apply_with_gradient!. The adjoints are the derivatives of the end result of the computation with respect to the two return values. With accumulate, the gradients are added to the arrays.
Wraps cutensornetExpectationComputeWithGradientsBackward.
cuTensorNet.configure! — Function
configure!(x, attr, value) -> xSet a configuration attribute of a state or a computation on it. The attribute is given by NVIDIA's enum for the type of x (cutensornetStateAttributes_t, cutensornetAccessorAttributes_t, ...), e.g. CUTENSORNET_EXPECTATION_CONFIG_NUM_HYPER_SAMPLES, and value must have the type that NVIDIA documents for it. Call it before prepare!.
Wraps cutensornetStateConfigure, cutensornetAccessorConfigure and the like.
cuTensorNet.contract! — Method
contract!(net::CuNetwork; accumulate=false, slices=nothing, stream=stream()) -> outputContract the prepared network into its output tensor, which is returned. With accumulate, the result is added to the output. slices, a CuTensorNetworkSliceGroup, limits the contraction to some of the slices, e.g. to distribute it.
Wraps cutensornetNetworkContract.
cuTensorNet.cuda_version — Method
cuTensorNet.cuda_version() -> VersionNumberThe version of the CUDA runtime that cuTensorNet was built with.
cuTensorNet.details — Method
details(state::CuNetworkState) -> (; extents, strides)The extents and strides of the tensors that compute! computes, one entry per tensor.
Wraps cutensornetGetOutputStateDetails.
cuTensorNet.discarded_weight — Method
discarded_weight(info::CuTensorSVDInfo) -> Float64The discarded weight of the truncation: the sum of the squares of the discarded singular values, relative to the sum of the squares of all of them.
cuTensorNet.enable_logging — Function
cuTensorNet.enable_logging(enable::Bool=true)Forward log messages from cuTensorNet to Julia's logging system. API and kernel traces are reported at Debug level, performance hints at Info level, and problems at Error level. Starting Julia with JULIA_DEBUG=cuTensorNet enables this automatically, and also shows the Debug-level messages.
cuTensorNet.extract_tensor! — Method
extract_tensor!(output::CuArray{T}, x::CuStateProjectionMPS{T}, env::Pair; stream=stream())
-> outputExtract the MPS tensor excluded by the environment env into output.
Wraps cutensornetStateProjectionMPSExtractTensor.
cuTensorNet.finalize_mps! — Method
finalize_mps!(state::CuNetworkState, extents::Vector{<:Vector{<:Integer}};
boundary_condition=CUTENSORNET_BOUNDARY_CONDITION_OPEN,
svd_algorithm=CUTENSORNET_TENSOR_SVD_ALGO_GESVDJ) -> stateHave compute! compute the state as a matrix product state, with tensors of at most the given extents, laid out as for initialize_mps!. The SVD used to truncate it can be configured with configure! and CUTENSORNET_STATE_CONFIG_MPS_SVD_*; the algorithm defaults to Jacobi (gesvdj), as NVIDIA's default fails for some states.
Wraps cutensornetStateFinalizeMPS.
cuTensorNet.flop_count — Method
flop_count(info::CuTensorNetworkContractionOptimizerInfo) -> Float64The estimated number of floating-point operations of the contraction along this path.
cuTensorNet.flops — Function
flops(x) -> Float64The estimated number of floating-point operations of the prepared state or computation.
cuTensorNet.full_extent — Method
full_extent(info::CuTensorSVDInfo) -> Int64The number of singular values before truncation.
cuTensorNet.functional — Method
cuTensorNet.functional() -> BoolWhether cuTensorNet was loaded and initialized successfully.
cuTensorNet.gate_split! — Method
gate_split!(A, modes_a, B, modes_b, G, modes_g, U, modes_u, S, V, modes_v;
algo=CUTENSORNET_GATE_SPLIT_ALGO_DIRECT, svd_config=SVDConfig(), stream, ...)
-> U, S, V, info
gate_split!(A::CuTensor, B::CuTensor, G::CuTensor, U::CuTensor, S, V::CuTensor; ...)
-> U, S, V, infoApply the two-site gate G to the tensors A and B, and split the result again. This is how a gate is applied to a matrix product state: A and B share a bond, and the result is split with a truncated SVD into U and V, with singular values S. algo (a cutensornetGateSplitAlgo_t) selects whether the full tensor is decomposed (DIRECT) or A and B are first reduced by QR (REDUCED), and svd_config the truncation, as in tensor_svd!.
Wraps cutensornetGateSplit.
cuTensorNet.handle — Method
cuTensorNet.handle()The cuTensorNet handle of the current task, for its active context, for calling the C API of cuTensorNet (cuTensorNet.cutensornet*) directly. It converts to a cutensornetHandle_t. The handle is borrowed: don't destroy it or change its settings, and don't keep it across tasks. Its fields are not part of the API.
cuTensorNet.info — Function
info(x, attr, R) -> RRead an information attribute of a prepared state or computation on it, such as CUTENSORNET_EXPECTATION_INFO_FLOPS, as a value of type R.
Wraps cutensornetStateGetInfo, cutensornetAccessorGetInfo and the like.
cuTensorNet.initialize_mps! — Method
initialize_mps!(state::CuNetworkState{T}, tensors::Vector{<:CuArray{T}};
boundary_condition=CUTENSORNET_BOUNDARY_CONDITION_OPEN) -> stateStart the state from a matrix product state with one tensor per state mode, instead of from the vacuum state. Each tensor has the modes (left bond, state mode, right bond), without the outer bonds at the boundaries of an open chain.
Wraps cutensornetStateInitializeMPS.
cuTensorNet.insert_tensor! — Method
insert_tensor!(x::CuStateProjectionMPS{T}, env::Pair, input::CuArray{T}; ortho=nothing,
stream=stream()) -> xInsert input as the MPS tensor excluded by the environment env, moving the orthogonality center to ortho, given as for CuStateProjectionMPS (0 => 2 for site 1). It is the site of a one-site environment (the default), one of the sites of a two-site environment, or a site next to the bond of a zero-site environment.
Wraps cutensornetStateProjectionMPSInsertTensor.
cuTensorNet.marginal_kind — Method
marginal_kind(x::CuStateMarginal) -> cutensornetMarginalKind_tWhether the prepared marginal is computed as a full density matrix or as its diagonal.
cuTensorNet.num_sliced_modes — Method
num_sliced_modes(info::CuTensorNetworkContractionOptimizerInfo) -> Int32The number of modes that are sliced over.
cuTensorNet.num_slices — Method
num_slices(info::CuTensorNetworkContractionOptimizerInfo) -> Int64The number of slices the contraction is split into, so that it fits the workspace limit given to rehearse_contraction.
cuTensorNet.pack — Method
pack(info::CuTensorNetworkContractionOptimizerInfo) -> Vector{UInt8}Serialize a contraction path, so that it can be reused without searching again, with unpack! or CuTensorNetworkContractionOptimizerInfo.
Wraps cutensornetContractionOptimizerInfoPackData.
cuTensorNet.prepare! — Function
prepare!(x; max_workspace=2^30, preference=CUTENSORNET_WORKSIZE_PREF_RECOMMENDED,
stream=stream()) -> xPrepare a state, or a computation on it, for compute! (or sample!, compute_env! and the like), using at most max_workspace bytes of workspace, which this allocates. Prepare a state again after applying more operators to it, or changing whether one is unitary. Applying an operator to a state invalidates the computations created on it before (accessors, expectations, marginals, samplers): create those again.
Wraps cutensornetStatePrepare, cutensornetAccessorPrepare and the like.
cuTensorNet.prepare_contraction! — Method
prepare_contraction!(net::CuNetwork; gradients=false,
preference=CUTENSORNET_WORKSIZE_PREF_RECOMMENDED) -> netAllocate the workspace for contracting the network along its contraction path, and prepare the contraction. This is needed before autotune! and contract!, and with gradients = true before compute_gradients!. preference (a cutensornetWorksizePref_t) selects how much workspace to allocate.
Wraps cutensornetNetworkPrepareContraction and cutensornetNetworkPrepareGradientsBackward.
cuTensorNet.purge_cache! — Function
purge_cache!(net::CuNetwork) -> netDrop the intermediate results cached because of inputs added with constant = true. Call this after changing the contents of such an input.
Wraps cutensornetWorkspacePurgeCache.
cuTensorNet.reduced_extent — Method
reduced_extent(info::CuTensorSVDInfo) -> Int64The number of singular values kept after truncation, k. Only the first k singular values are valid. When k is smaller than the extent of the mode that U and V share, the factors are stored packed, as arrays with extent k for that mode in the first elements of U and V: for a kmax×n matrix V, the factor is reshape(view(V, 1:k*n), k, n), not V[1:k, :].
cuTensorNet.rehearse_contraction — Function
rehearse_contraction(net::CuNetwork, max_workspace_size, config=OptimizerConfig())
-> CuTensorNetworkContractionOptimizerInfoFind a contraction path for the network that needs at most max_workspace_size bytes of workspace, slicing the contraction if needed, and attach it to the network. The search is configured with OptimizerConfig.
Wraps cutensornetContractionOptimize.
cuTensorNet.sample! — Method
sample!(x::CuStateSampler, num_shots; stream=stream()) -> Matrix{Int64}Draw num_shots samples of the sampler's modes, as a matrix with a column of mode values for each sample. Configure CUTENSORNET_SAMPLER_CONFIG_DETERMINISTIC with configure! for reproducible samples.
Wraps cutensornetSamplerSample.
cuTensorNet.set_adjoint! — Method
set_adjoint!(net::CuNetwork{T}, adjoint::CuArray{T}) -> netSet the adjoint of the output, which seeds the backward pass of compute_gradients!. It is the derivative of the final result with respect to the output tensor, and has the size of the output.
Wraps cutensornetNetworkSetAdjointTensorMemory.
cuTensorNet.set_gradient! — Method
set_gradient!(net::CuNetwork{T}, id, gradient::CuArray{T}) -> netSet the array that compute_gradients! writes the gradient with respect to input id to. It has the size of that input, which must have been added with requires_gradient = true.
Wraps cutensornetNetworkSetGradientTensorMemory.
cuTensorNet.set_optimizer_info! — Method
set_optimizer_info!(net::CuNetwork, info::CuTensorNetworkContractionOptimizerInfo) -> netUse the contraction path info for the network, e.g. one found for another network of the same shape, or one changed with attribute! or unpack!.
Wraps cutensornetNetworkSetOptimizerInfo.
cuTensorNet.set_output! — Method
set_output!(net::CuNetwork{T}, tensor::CuArray{T}, modes) -> netSet tensor as the output of the network, with an integer label for each of its modes. Modes of the inputs that are not in modes are summed over.
Wraps cutensornetNetworkSetOutputTensor.
cuTensorNet.tensor_ids — Method
tensor_ids(net::CuNetwork, num_attr, list_attr) -> Vector{Int32}The ids of the input tensors with a qualifier, given by the network attributes for their number and their list, e.g. CUTENSORNET_NETWORK_INPUT_TENSORS_NUM_CONSTANT and CUTENSORNET_NETWORK_INPUT_TENSORS_CONSTANT.
cuTensorNet.tensor_info — Method
tensor_info(x::CuStateProjectionMPS, env::Pair) -> (; extents, strides)The extents of the MPS tensor excluded by the environment env, and the strides NVIDIA recommends for it.
Wraps cutensornetStateProjectionMPSGetTensorInfo.
cuTensorNet.tensor_qr! — Method
tensor_qr!(A, modes_a, Q, modes_q, R, modes_r; stream, workspace_preference, memspace)
-> Q, R
tensor_qr!(A::CuTensor, Q::CuTensor, R::CuTensor; ...) -> Q, RCompute the QR decomposition of the tensor A, writing the factors to Q and R. The modes of A are split between Q and R by their labels: Q and R share one new mode, the modes of Q are rows and those of R are columns of the matrix being decomposed. Mode labels can be integers or characters. A is not modified.
Wraps cutensornetTensorQR. workspace_preference is a cutensornetWorksizePref_t, and memspace a cutensornetMemspace_t.
cuTensorNet.tensor_svd! — Method
tensor_svd!(A, modes_a, U, modes_u, S, V, modes_v; svd_config=SVDConfig(), stream, ...)
-> U, S, V, info
tensor_svd!(A::CuTensor, U::CuTensor, S, V::CuTensor; ...) -> U, S, V, infoCompute the (truncated) singular value decomposition of the tensor A, writing the factors to U and V, and the singular values to the real vector S. The modes of A are split between U and V as in tensor_qr!. The truncation is configured with SVDConfig, and its result described by the returned CuTensorSVDInfo. When it reduces the shared mode, the factors are stored packed, as described at reduced_extent.
Wraps cutensornetTensorSVD.
cuTensorNet.unpack! — Method
unpack!(info::CuTensorNetworkContractionOptimizerInfo, data::Vector{UInt8}) -> infoReplace the contraction path in info by one serialized with pack. A path that belongs to a network must be attached to it again with set_optimizer_info!.
Wraps cutensornetUpdateContractionOptimizerInfoFromPackedData.
cuTensorNet.update! — Method
update!(state::CuNetworkState{T}, id, operator::CuArray{T}; unitary=false) -> stateUse new data for the operator id, which must have been applied with immutable = false. Also call this after changing the operator in place.
Wraps cutensornetStateUpdateTensorOperator.
cuTensorNet.update_coefficient! — Method
update_coefficient!(x::CuStateProjectionMPS, coefficient) -> xChange the coefficient that the state is multiplied with in the projection.
Wraps cutensornetStateProjectionMPSUpdateCoefficients.
cuTensorNet.update_dual_tensors! — Method
update_dual_tensors!(x::CuStateProjectionMPS{T}, dual_tensors::Vector{<:CuArray{T}};
ortho=nothing, stream=stream()) -> xReplace the dual tensors of the projection by others with the same extents, with the orthogonality center at ortho (given as for CuStateProjectionMPS), or none.
Wraps cutensornetStateProjectionMPSUpdateDualTensors.
cuTensorNet.update_gradient! — Method
update_gradient!(state::CuNetworkState{T}, id, gradient::CuArray{T}) -> stateWrite the gradient with respect to the operator id to a different array.
Wraps cutensornetStateUpdateTensorOperatorGradient.
cuTensorNet.version — Method
cuTensorNet.version() -> VersionNumberThe version of the cuTensorNet library in use, not that of the CUDA toolkit.