tnc/_tutorial/
constructing_tns.rs

1//! # Constructing tensor networks
2//!
3//! There are multiple ways to construct tensors and tensor networks.
4//!
5//! ## Quantum
6//!
7//! ### OpenQASM2 code
8//! If the goal is to clasically simulate quantum circuits, one can directly load
9//! OpenQASM2 code and construct a [`Circuit`] out of it using [`import_qasm`].
10//!
11//! <div class="warning">
12//! This library implements many standard gates and when it encounters one in the
13//! QASM code, it will not look for a gate definition; only when it doesn't know the
14//! gate, it will decompose the gate using an earlier gate definition in the QASM
15//! code.
16//! </div>
17//!
18//! From the circuit, we can then construct different tensor networks, depending on
19//! what we want to compute:
20//! - [`into_amplitude_network`] creates a tensor network that computes the
21//!   amplitude(s) to one or more states.
22//! - [`into_statevector_network`] creates a tensor network that computes the full
23//!   statevector
24//! - [`into_expectation_value_network`]: creates a tensor network that computes the
25//!   expectation value of the circuit with respect to `Z` observables on each qubit
26//!
27//! [`into_amplitude_network`]: Circuit::into_amplitude_network
28//! [`into_statevector_network`]: Circuit::into_statevector_network
29//! [`into_expectation_value_network`]: Circuit::into_expectation_value_network
30//!
31//! ### Circuit builder
32//! Similar to importing QASM2 code, the [`Circuit`] struct can also directly be used
33//! to construct tensor networks that simulate quantum circuits.
34//!
35//! ### Sycamore circuit
36//! There are special methods to construct tensor networks corresponding to the
37//! quantum circuits of the Sycamore experiment ([Quantum supremacy using a
38//! programmable superconducting processor](
39//! https://www.nature.com/articles/s41586-019-1666-5) (Arute et al.)). See the
40//! [`sycamore_circuit`] method.
41//!
42//! ## HDF5 files
43//! Tensors and tensor networks can also be saved and loaded from HDF5 files, see the
44//! functions in [`hdf5`]. The structure of the files is:
45//! ```text
46//! [Group name="tensors"]
47//!     [Dataset name="tensorA" datatype=double complex tensor]
48//!         [Attribute name="bids" datatype=int list]
49//!     [Dataset name="tensorB" datatype=double complex tensor]
50//!         [Attribute name="bids" datatype=int list]
51//!     ...
52//! ```
53//! where `bids` are the leg IDs.
54//!
55//! ## General tensor networks
56//! The [`Tensor`] struct can be used to directly construct arbitrary tensors and
57//! tensor networks. Tensors are created from a list of leg IDs and the corresponding
58//! dimensions of these legs. Connected tensors are identified by having at least one
59//! leg ID in common. The corresponding bond dimensions have to match.
60//!
61//! Tensors without data can already be used for e.g. finding a contraction path, but
62//! if you want to actually contract a tensor network, the tensors need data. For
63//! this, there is the [`set_tensor_data`] method which takes a variant of
64//! [`TensorData`].
65//!
66//! [`set_tensor_data`]: Tensor::set_tensor_data
67//!
68//! A normal tensor network is a list of tensors. However, this library also supports
69//! hierarchical tensor network structures, which are detailed in another tutorial.
70#![allow(unused_imports)]
71use crate::builders::circuit_builder::Circuit;
72use crate::builders::sycamore_circuit::sycamore_circuit;
73use crate::hdf5;
74use crate::qasm::import_qasm;
75use crate::tensornetwork::tensor::Tensor;
76use crate::tensornetwork::tensordata::TensorData;
77
78pub use crate::_tutorial as table_of_contents;