### Obtain Predefined Operator for 'S=1/2' Site Index Source: https://docs.itensor.org/ITensorMPS/stable/examples/Physics Demonstrates how to get a predefined operator, such as 'Sz', for a given Index tagged with 'S=1/2'. This is a common operation when working with spin-1/2 systems. ```julia using ITensors, ITensorMPS op("Sz",s) ``` -------------------------------- ### Example: Apply One-Site Gates to MPS Source: https://docs.itensor.org/ITensorMPS/stable/MPSandMPO Demonstrates applying a list of one-site gates (like Pauli operators) to an MPS. The example shows how to define operators, create gates, apply them, and verify the result against an exact calculation. ```julia N = 3 ITensors.op(::OpName"σx", ::SiteType"S=1/2", s::Index) = 2*op("Sx", s) ITensors.op(::OpName"σz", ::SiteType"S=1/2", s::Index) = 2*op("Sz", s) # Make the operator list. os = [("σx", n) for n in 1:N] append!(os, [("σz", n) for n in 1:N]) @show os s = siteinds("S=1/2", N) gates = ops(os, s) # Starting state |↑↑↑⟩ ψ0 = MPS(s, "↑") # Apply the gates. ψ = apply(gates, ψ0; cutoff = 1e-15) # Test against exact (full) wavefunction prodψ = apply(gates, prod(ψ0)) @show prod(ψ) ≈ prodψ # The result is: # σz₃ σz₂ σz₁ σx₃ σx₂ σx₁ |↑↑↑⟩ = -|↓↓↓⟩ @show inner(ψ, MPS(s, "↓")) == -1 ``` -------------------------------- ### Construct MPO using Custom Operator in OpSum Source: https://docs.itensor.org/ITensorMPS/stable/examples/Physics Demonstrates how to use a custom operator ('Pup') within the OpSum system to construct a Matrix Product Operator (MPO). This example creates an MPO that is the sum of 'Pup' operators on each site of a spin system. ```julia using ITensors, ITensorMPS N = 100 sites = siteinds("S=1/2",N) os = OpSum() for n=1:N os += "Pup",n end P = MPO(os,sites) ``` -------------------------------- ### Example: Apply Nonlocal Two-Site and One-Site Gates Source: https://docs.itensor.org/ITensorMPS/stable/MPSandMPO Illustrates applying a mix of nonlocal two-site gates (like CX) and one-site gates to an MPS. The example defines the CX gate and demonstrates its application to a specific initial state, verifying the outcome. ```julia # 2-site gate function ITensors.op(::OpName"CX", ::SiteType"S=1/2", s1::Index, s2::Index) mat = [1 0 0 0 0 1 0 0 0 0 0 1 0 0 1 0] return itensor(mat, s2', s1', s2, s1) end os = [("CX", 1, 3), ("σz", 3)] @show os # Start with the state |↓↑↑⟩ ψ0 = MPS(s, n -> n == 1 ? "↓" : "↑") # The result is: # σz₃ CX₁₃ |↓↑↑⟩ = -|↓↑↓⟩ ψ = apply(ops(os, s), ψ0; cutoff = 1e-15) @show inner(ψ, MPS(s, n -> n == 1 || n == 3 ? "↓" : "↑")) == -1 ``` -------------------------------- ### Generate Multiple Operators using `op` - Julia Source: https://docs.itensor.org/ITensorMPS/stable/examples/Physics This example shows how to generate multiple ITensor operators from a collection of site indices. It first creates an array of site indices for 'S=3/2' sites and then uses the `op` function to get specific operators ('Sz' and 'S+') for different site positions. ```julia using ITensors, ITensorMPS N = 100 sites = siteinds("S=3/2",N) Sz1 = op("Sz",sites[1]) Sp3 = op("S+",sites[3]) ``` -------------------------------- ### Obtain Specific Operator from Site Index Array Source: https://docs.itensor.org/ITensorMPS/stable/examples/Physics Illustrates how to retrieve a specific operator, like 'Sz', from an array of site indices. This example targets the operator on the 4th site (index 4) of the 'sites' array. ```julia using ITensors, ITensorMPS Sz4 = op("Sz",sites[4]) ``` -------------------------------- ### Run DMRG with Custom Entanglement Observer - Julia Source: https://docs.itensor.org/ITensorMPS/stable/examples/DMRG A complete Julia code example demonstrating the construction and usage of the `EntanglementObserver` within a DMRG calculation. It sets up a Hamiltonian, an initial MPS, and then calls the `dmrg` function, passing the custom observer. The output includes the calculated entanglement entropy for each bond. Dependencies include `ITensors` and `ITensorMPS`. ```julia using ITensors, ITensorMPS mutable struct EntanglementObserver <: AbstractObserver end function ITensorMPS.measure!(o::EntanglementObserver; bond, psi, half_sweep, kwargs...) wf_center, other = half_sweep==1 ? (psi[bond+1],psi[bond]) : (psi[bond],psi[bond+1]) U,S,V = svd(wf_center, uniqueinds(wf_center,other)) SvN = 0.0 for n=1:dim(S, 1) p = S[n,n]^2 SvN -= p * log(p) end println(" Entanglement across bond $bond = $SvN") end let N = 100 s = siteinds("S=1/2",N) a = OpSum() for n=1:N-1 a += "Sz",n,"Sz",n+1 a += 0.5,"S+",n,"S-",n+1 a += 0.5,"S-",n,"S+",n+1 end H = MPO(a,s) psi0 = random_mps(s;linkdims=4) nsweeps = 5 maxdim = [10,20,80,160] cutoff = 1E-8 observer = EntanglementObserver() energy,psi = dmrg(H,psi0;nsweeps,maxdim,cutoff,observer,outputlevel=2) return end ``` -------------------------------- ### Define Custom Operator 'P1' for 'Boson' using Array Comprehension Source: https://docs.itensor.org/ITensorMPS/stable/examples/Physics An alternative method to define a custom operator ('P1') for a 'Boson' site type using Julia's array comprehension syntax. This achieves the same result as the previous example but in a more compact form. ```julia using ITensors, ITensorMPS ITensors.op(::OpName"P1", ::SiteType"Boson", d::Int) = [(i == j == 1) ? 1.0 : 0.0 for i in 1:d, j in 1:d] ``` -------------------------------- ### Create ITensor MPS from ITensor Source: https://docs.itensor.org/ITensorMPS/stable/examples/MPSandMPO Demonstrates how to create an MPS approximation of an existing ITensor. It uses cutoff and maxdim parameters to control the approximation accuracy during factorization. Requires ITensors library. ```julia cutoff = 1E-8 maxdim = 10 i,j,k,l,m = ind(T) T = random_itensor(i,j,k,l,m) M = MPS(T,(i,j,k,l,m);cutoff=cutoff,maxdim=maxdim) ``` -------------------------------- ### Generate Array of Site Indices for 'S=1/2' System Source: https://docs.itensor.org/ITensorMPS/stable/examples/Physics Shows how to generate an array of site indices for a system of a specified size (N) with a given site type ('S=1/2'). This is often a prerequisite for obtaining operators on specific sites. ```julia using ITensors, ITensorMPS N = 10 sites = siteinds("S=1/2",N) ``` -------------------------------- ### DMRG with Mixed Spin Types in Julia Source: https://docs.itensor.org/ITensorMPS/stable/examples/DMRG This example demonstrates a DMRG calculation on a spin chain with alternating S=1/2 and S=1 sites. It defines site indices with different physical tags, constructs a Hamiltonian with tunable couplings between same and different spin sites using OpSum, and specifies DMRG parameters. The calculation then proceeds to find the ground state. This requires the ITensors and ITensorMPS packages. ```Julia using ITensors, ITensorMPS let N = 100 # Make an array of N Index objects with alternating # "S=1/2" and "S=1" tags on odd versus even sites # (The first argument n->isodd(n) ... is an # on-the-fly function mapping integers to strings) sites = siteinds(n->isodd(n) ? "S=1/2" : "S=1",N) # Couplings between spin-half and # spin-one sites: Jho = 1.0 # half-one coupling Jhh = 0.5 # half-half coupling Joo = 0.5 # one-one coupling os = OpSum() for j=1:N-1 os += 0.5*Jho,"S+",j,"S-",j+1 os += 0.5*Jho,"S-",j,"S+",j+1 os += Jho,"Sz",j,"Sz",j+1 end for j=1:2:N-2 os += 0.5*Jhh,"S+",j,"S-",j+2 os += 0.5*Jhh,"S-",j,"S+",j+2 os += Jhh,"Sz",j,"Sz",j+2 end for j=2:2:N-2 os += 0.5*Joo,"S+",j,"S-",j+2 os += 0.5*Joo,"S-",j,"S+",j+2 os += Joo,"Sz",j,"Sz",j+2 end H = MPO(os,sites) nsweeps = 10 maxdim = [10,10,20,40,80,100,140,180,200] cutoff = [1E-8] psi0 = random_mps(sites;linkdims=4) energy,psi = dmrg(H,psi0;nsweeps,maxdim,cutoff) return end ``` -------------------------------- ### Obtain Custom Operator 'Pup' for 'S=1/2' Site Index Source: https://docs.itensor.org/ITensorMPS/stable/examples/Physics Shows how to obtain the custom 'Pup' operator for an 'S=1/2' site index after extending the `op` function definition. This allows using the new operator name seamlessly. ```julia using ITensors, ITensorMPS s = siteind("S=1/2") Pup = op("Pup",s) ``` -------------------------------- ### Create Custom Operator from Matrix Source: https://docs.itensor.org/ITensorMPS/stable/examples/Physics Explains how to create a custom ITensor operator by passing a matrix (M) and a site Index (s). The matrix must have dimensions compatible with the Index's Hilbert space. ```julia using ITensors, ITensorMPS M = [1/2 0 ; 0 -1/2] Sz = op(M,s) ``` -------------------------------- ### Create MPS from Julia Array Source: https://docs.itensor.org/ITensorMPS/stable/examples/MPSandMPO Shows how to convert a Julia array (multi-dimensional or 1D) into an MPS approximation. It involves creating site indices and then using the MPS constructor with truncation parameters. Requires ITensors and ITensorMPS libraries. ```julia d = 2 N = 5 A = randn(d,d,d,d,d) # Or A = randn(d^N) sites = siteinds(d,N) cutoff = 1E-8 maxdim = 10 M = MPS(A,sites;cutoff=cutoff,maxdim=maxdim) ``` -------------------------------- ### Example: Time Evolution with Heisenberg Model Source: https://docs.itensor.org/ITensorMPS/stable/MPSandMPO Demonstrates performing time evolution using the TEBD method with the Heisenberg model's nearest-neighbor interaction (S⋅S). It defines the exponential operator and applies it sequentially to an MPS representing an initial state. ```julia # Define the nearest neighbor term `S⋅S` for the Heisenberg model function ITensors.op(::OpName"expS⋅S", ::SiteType"S=1/2", s1::Index, s2::Index; τ::Number) O = 0.5 * op("S+", s1) * op("S-", s2) + 0.5 * op("S-", s1) * op("S+", s2) + op("Sz", s1) * op("Sz", s2) return exp(τ * O) end τ = -0.1im os = [("expS⋅S", (1, 2), (τ = τ,)), ("expS⋅S", (2, 3), (τ = τ,))] ψ0 = MPS(s, n -> n == 1 ? "↓" : "↑") expτH = ops(os, s) ψτ = apply(expτH, ψ0) ``` -------------------------------- ### Obtain Custom Operator 'Pup' for Specific Site in Array Source: https://docs.itensor.org/ITensorMPS/stable/examples/Physics Illustrates obtaining the custom 'Pup' operator for specific sites within an array of 'S=1/2' site indices. This is useful for applying the custom operator to particular locations in a system. ```julia using ITensors, ITensorMPS N = 40 s = siteinds("S=1/2",N) Pup1 = op("Pup",s[1]) Pup3 = op("Pup",s[3]) ``` -------------------------------- ### Write MPO to HDF5 in Julia Source: https://docs.itensor.org/ITensorMPS/stable/examples/MPSandMPO Demonstrates how to save a Matrix Product Operator (MPO) to an HDF5 file. The process is analogous to writing an MPS, using the `MPO` type when reading back from the file. ```julia using HDF5 f = h5open("my_mpo_file.h5", "w") write(f, "mpo_data", mpo_object) # Replace mpo_object with your MPO close(f) ``` -------------------------------- ### Convert OpSum to MPO Source: https://docs.itensor.org/ITensorMPS/stable/OpSum Shows how to convert an OpSum object into a Matrix Product Operator (MPO). Includes examples for specifying the element type and controlling block splitting for sparsity. ```julia os = OpSum() os += "Sz",1,"Sz",2 os += "Sz",2,"Sz",3 os += "Sz",3,"Sz",4 sites = siteinds("S=1/2",4) H = MPO(os,sites) H = MPO(Float32,os,sites) H = MPO(os,sites; splitblocks=false) ``` -------------------------------- ### Sample from MPS in Julia Source: https://docs.itensor.org/ITensorMPS/stable/examples/MPSandMPO Demonstrates how to generate random samples from a Matrix Product State (MPS) which represents a probability distribution. The `sample` function provides perfect sampling without autocorrelation. The MPS must be orthogonalized to the first site for efficiency. ```julia using ITensors, ITensorMPS N = 10 # number of sites d = 3 # dimension of each site chi = 16 # bond dimension of the MPS s = siteinds(d,N) psi = random_mps(s;linkdims=chi) v1 = sample(psi) v2 = sample(psi) v3 = sample(psi) println(v1) println(v2) println(v3) ``` -------------------------------- ### Read MPO from HDF5 in Julia Source: https://docs.itensor.org/ITensorMPS/stable/examples/MPSandMPO Shows how to load an MPO object from an HDF5 file. Similar to reading an MPS, you specify the file, the dataset name, and the type `MPO` to correctly interpret the stored data. ```julia using HDF5 f = h5open("my_mpo_file.h5", "r") mpo_object = read(f, "mpo_data", MPO) # Replace mpo_object with your desired variable name close(f) ``` -------------------------------- ### Create and Print 'Sz' Operator ITensor - Julia Source: https://docs.itensor.org/ITensorMPS/stable/examples/Physics This snippet demonstrates how to create an ITensor representation of the 'Sz' operator for a given Index with the 'S=3/2' tag. It first defines a site Index and then uses the `op` function to obtain the 'Sz' operator, which is then printed. ```julia using ITensors, ITensorMPS s = Index(4,"S=3/2") Sz = op("Sz",s) println(Sz) ``` -------------------------------- ### DMRGObserver Constructor with Operators, Sites, and Convergence Settings Source: https://docs.itensor.org/ITensorMPS/stable/DMRGObserver This constructor initializes a DMRGObserver by taking a vector of operator names (strings), the basis sites for the MPS/MPO, and optional parameters for energy tolerance and minimum sweeps. The specified operators will be measured on each site at every DMRG step. ```julia DMRGObserver(ops::Vector{String}, sites::Vector{<:Index}; energy_tol=0.0, minsweeps=2, energy_type=Float64) ``` -------------------------------- ### ITensors.SiteTypes.siteinds - Get All Site Indices of MPO Source: https://docs.itensor.org/ITensorMPS/stable/MPSandMPO Gets a Vector of IndexSets of all the site indices of an MPO. ```APIDOC ## ITensors.SiteTypes.siteinds - Get All Site Indices of MPO ### Description Get a Vector of IndexSets of all the site indices of M. ### Method `siteinds(M::MPO; kwargs...) ### Endpoint N/A (This is a library function, not a REST endpoint) ### Parameters #### Path Parameters None #### Query Parameters - **kwargs** - Optional keyword arguments for filtering indices (e.g., `plev`, `tags`). #### Request Body None ### Request Example ```julia # Assuming M is an MPO # all_indices = siteinds(M) ``` ### Response #### Success Response (200) - **all_site_indices** (Vector{IndexSet}) - A vector containing IndexSets of all site indices for each tensor in the MPO. #### Response Example ```json { "all_site_indices": [ ["Index(\"d=2, Site; \"1\")", "Index(\"l=1\")"], ["Index(\"d=2, Site; \"2\")", "Index(\"l=1\")", "Index(\"l=2\")"], ["Index(\"d=2, Site; \"3\")", "Index(\"l=2\")", "Index(\"l=3\")"], ["Index(\"d=2, Site; \"4\")", "Index(\"l=3\")"] ] } ``` ``` -------------------------------- ### Initialize and Use DMRGObserver for Sz Measurements and Early Stopping Source: https://docs.itensor.org/ITensorMPS/stable/DMRGObserver This snippet demonstrates how to initialize a DMRGObserver to measure the 'Sz' operator on each site and stop the DMRG calculation early if the energy converges to a relative precision of 1E-7. It then shows how to retrieve and print the total Sz values after each sweep. ```julia Sz_observer = DMRGObserver(["Sz"],sites,energy_tol=1E-7) energy, psi = dmrg(H,psi0,sweeps,observer=Sz_observer) for (sw,Szs) in enumerate(measurements(Sz_observer)[ "Sz"]) println("Total Sz after sweep $sw = ", sum(Szs)/N) end ``` -------------------------------- ### ITensors.SiteTypes.siteind - Get First Site Index of MPO Source: https://docs.itensor.org/ITensorMPS/stable/MPSandMPO Gets the first site Index of an MPO, by default with prime level 0. ```APIDOC ## ITensors.SiteTypes.siteind - Get First Site Index of MPO ### Description Get the first site Index of the MPO found, by default with prime level 0. ### Method `siteind(M::MPO, j::Int; plev = 0, kwargs...) ### Endpoint N/A (This is a library function, not a REST endpoint) ### Parameters #### Path Parameters None #### Query Parameters - **plev** (Integer) - The prime level to filter by. Defaults to 0. - **kwargs** - Optional keyword arguments for filtering indices (e.g., `tags`). #### Request Body None ### Request Example ```julia # Assuming M is an MPO and j is an integer site index # first_site_index = siteind(M, j) # first_site_index_plev1 = siteind(M, j; plev=1) ``` ### Response #### Success Response (200) - **first_site_index** (Index or Nothing) - The first site index found matching the criteria, or `nothing`. #### Response Example ```json { "first_site_index": "Index(\"d=2, Site; \"1\")" } ``` ```json { "first_site_index": null } ``` ``` -------------------------------- ### ITensors.SiteTypes.siteind - Get First Site Index of MPS Source: https://docs.itensor.org/ITensorMPS/stable/MPSandMPO Gets the first site Index of an MPS, returning nothing if none is found. ```APIDOC ## ITensors.SiteTypes.siteind - Get First Site Index of MPS ### Description Get the first site Index of the MPS. Return `nothing` if none is found. ### Method `siteind(M::MPS, j::Int; kwargs...) ### Endpoint N/A (This is a library function, not a REST endpoint) ### Parameters #### Path Parameters None #### Query Parameters - **kwargs** - Optional keyword arguments for filtering indices (e.g., `plev`, `tags`). #### Request Body None ### Request Example ```julia # Assuming M is an MPS and j is an integer site index # first_site_index = siteind(M, j) ``` ### Response #### Success Response (200) - **first_site_index** (Index or Nothing) - The first site index found, or `nothing`. #### Response Example ```json { "first_site_index": "Index(\"d=2, Site; \"1\")" } ``` ```json { "first_site_index": null } ``` ``` -------------------------------- ### ITensorMPS.firstsiteinds - Get First Site Index of Each Site in MPO Source: https://docs.itensor.org/ITensorMPS/stable/MPSandMPO Gets a Vector of the first site Index found on each site of an MPO. ```APIDOC ## ITensorMPS.firstsiteinds - Get First Site Index of Each Site in MPO ### Description Get a Vector of the first site Index found on each site of M. By default, it finds the first site Index with prime level 0. ### Method `firstsiteinds(M::MPO; kwargs...) ### Endpoint N/A (This is a library function, not a REST endpoint) ### Parameters #### Path Parameters None #### Query Parameters - **kwargs** - Optional keyword arguments for filtering indices (e.g., `plev`, `tags`). #### Request Body None ### Request Example ```julia # Assuming M is an MPO # first_indices = firstsiteinds(M) ``` ### Response #### Success Response (200) - **first_site_indices** (Vector{Index}) - A vector containing the first site index for each site in the MPO. #### Response Example ```json { "first_site_indices": [ "Index(\"d=2, Site; \"4")", "Index(\"d=2, Site; \"3")", "Index(\"d=2, Site; \"2")", "Index(\"d=2, Site; \"1")" ] } ``` ``` -------------------------------- ### Create Qudit Site Indices Source: https://docs.itensor.org/ITensorMPS/stable/IncludedSiteTypes Demonstrates how to create site indices for 'Qudit' systems (which also alias 'Boson'). This includes creating a single 'Qudit' site or N sites, and configuring properties like dimension and number conservation. ```julia s = siteind("Qudit") sites = siteinds("Qudit",N) ``` ```julia sites = siteinds("Qudit",N; conserve_number=true) ``` -------------------------------- ### ITensors.SiteTypes.siteinds - Get Site Indices of MPS Source: https://docs.itensor.org/ITensorMPS/stable/MPSandMPO Gets a vector of site indices for an MPS, with options to retrieve the first, only, or all indices per tensor. ```APIDOC ## ITensors.SiteTypes.siteinds - Get Site Indices of MPS ### Description Get a vector of the first site Index found on each tensor of the MPS. Get a vector of the only site Index found on each tensor of the MPS. Errors if more than one is found. Get a vector of all site Indices found on each tensor of the MPS. Returns a Vector of IndexSets. ### Method `siteinds(M::MPS) `siteinds(::typeof(first), M::MPS) `siteinds(::typeof(only), M::MPS) `siteinds(::typeof(all), M::MPS) ### Endpoint N/A (This is a library function, not a REST endpoint) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```julia # Assuming M is an MPS # all_indices = siteinds(M) # first_indices = siteinds(first, M) # only_indices = siteinds(only, M) # Will error if multiple indices found # all_indices_set = siteinds(all, M) ``` ### Response #### Success Response (200) - **site_indices** (Vector{Index} or Vector{IndexSet}) - A vector containing the requested site indices. #### Response Example ```json { "site_indices": [ "Index(\"d=2, Site; \"1\")", "Index(\"d=2, Site; \"2\")" ] } ``` ```json { "site_indices": [ ["Index(\"d=2, Site; \"1\")", "Index(\"d=2, Site; \"1, p=1\")"], ["Index(\"d=2, Site; \"2\")"] ] } ``` ``` -------------------------------- ### Verify Site Properties - ITensor Source: https://docs.itensor.org/ITensorMPS/stable/tutorials/DMRG This snippet demonstrates how to print and inspect the properties of a single site index created by `siteinds`. It verifies that the index has the expected dimension (3 for S=1 spins) and carries the correct tag ('S=1'). This is useful for debugging and understanding the site setup. ```julia @show sites[1] ``` -------------------------------- ### Get First Site Index with ITensors.SiteTypes.siteind Source: https://docs.itensor.org/ITensorMPS/stable/MPSandMPO Gets the first site Index of an MPS, returning `nothing` if none is found. This function is useful for simple checks or when only the primary site index is needed. ```julia siteind(M::MPS, j::Int; kwargs...) ``` -------------------------------- ### Get Element Type of MPS/MPO using `eltype` Source: https://docs.itensor.org/ITensorMPS/stable/MPSandMPO Retrieves the element type of an MPS or MPO. This method always returns `ITensor`. To get the element type of the individual ITensors within the MPS/MPO, use `promote_itensor_eltype`. ```julia using ITensors, ITensorMPS s = siteinds("S=1/2", 3) M = random_mps(s) ep = eltype(M) # ep will be ITensor ``` -------------------------------- ### Initialize Spin Sites - ITensor Source: https://docs.itensor.org/ITensorMPS/stable/tutorials/DMRG This code initializes an array of ITensor Index objects representing S=1 spins. The `siteinds` function creates indices with a dimension of 3 and tags them with 'S=1', which is used later to correctly construct operators for these sites. This is a fundamental step for setting up quantum Hamiltonians in ITensor. ```julia N = 100 sites = siteinds("S=1",N) ``` -------------------------------- ### Create "tJ" Sites Source: https://docs.itensor.org/ITensorMPS/stable/IncludedSiteTypes Demonstrates how to create a single "tJ" site or a collection of N "tJ" sites. This is a fundamental step for setting up quantum systems with this site type. ```Julia s = siteind("tJ") sites = siteinds("tJ",N) ``` -------------------------------- ### Create QN-Conserving S=3/2 Site Index Source: https://docs.itensor.org/ITensorMPS/stable/examples/Physics This snippet demonstrates how to create a single site index of type "S=3/2" that conserves quantum numbers (Sz). The `siteind` function utilizes the previously defined `space` function to construct an Index that carries quantum number information. ```julia using ITensors, ITensorMPS s = siteind("S=3/2"; conserve_qns=true) ``` -------------------------------- ### DMRGObserver Constructor with Energy Tolerance and Minimum Sweeps Source: https://docs.itensor.org/ITensorMPS/stable/DMRGObserver This constructor allows the creation of a DMRGObserver with specified energy tolerance for early stopping and a minimum number of sweeps to be performed. It also allows setting the data type for storing energies. ```julia DMRGObserver(;energy_tol=0.0, minsweeps=2, energy_type=Float64) ``` -------------------------------- ### Get Number of Sites using `length` Source: https://docs.itensor.org/ITensorMPS/stable/MPSandMPO Returns the total number of sites in an MPS or MPO object. ```julia using ITensors, ITensorMPS s = siteinds("S=1/2", 5) M = random_mps(s) num_sites = length(M) println("Number of sites: ", num_sites) ``` -------------------------------- ### Create Array of QN-Conserving S=3/2 Site Indices Source: https://docs.itensor.org/ITensorMPS/stable/examples/Physics This code shows how to generate an array of N site indices, each of type "S=3/2" and conserving quantum numbers (Sz). The `siteinds` function, leveraging the custom `space` function, constructs multiple indices that carry quantum number information. ```julia using ITensors, ITensorMPS N = 100 sites = siteinds("S=3/2",N; conserve_qns=true) ``` -------------------------------- ### Get Length of ProjMPO (Julia) Source: https://docs.itensor.org/ITensorMPS/stable/ProjMPO Returns the length of the ProjMPO, which is equivalent to the length of the MPO used in its construction. ```julia length(P::ProjMPO) ``` -------------------------------- ### Create Qubit Operators with op() Source: https://docs.itensor.org/ITensorMPS/stable/IncludedSiteTypes Demonstrates how to create single-qubit operators using the `op` function, specifying the operator name and the site index. Supported operators include Pauli gates, Hadamard, Phase, rotations, and projection operators. ```julia H = op("H",s) H3 = op("H",sites[3]) ``` -------------------------------- ### Get QN Value by Name Source: https://docs.itensor.org/ITensorMPS/stable/SiteType Retrieves the integer value associated with a given string name from a Quantum Number (QN) object. ```julia val(q::QN,name) ``` -------------------------------- ### Get Element Type of ProjMPOSum Tensors Source: https://docs.itensor.org/ITensorMPS/stable/ProjMPOSum Deduces the element type (e.g., Float64, ComplexF64) of the tensors contained within a ProjMPOSum. ```julia eltype(P::ProjMPOSum) ``` -------------------------------- ### Get Noise-Term Coefficient for a Specific Sweep Source: https://docs.itensor.org/ITensorMPS/stable/Sweeps Retrieves the noise-term coefficient setting for a specific sweep `n` from the Sweeps object `sw`. ```julia noise(sw::Sweeps, n::Int) ``` -------------------------------- ### Get Number of Sweeps Source: https://docs.itensor.org/ITensorMPS/stable/Sweeps Retrieves the total number of sweeps defined in the Sweeps object. This can also be accessed using the `length` function. ```julia nsweep(sw::Sweeps) length(sw::Sweeps) ``` -------------------------------- ### Create S=3/2 Index using ITensor Source: https://docs.itensor.org/ITensorMPS/stable/examples/Physics This code snippet shows how to create a single ITensor Index representing an S=3/2 site. It utilizes the `siteind` function, which, along with the previously defined `space` function, ensures the index has the correct dimension (4) and appropriate default tags. This is a fundamental step in building ITensor models with custom site types. ```julia using ITensors, ITensorMPS s = siteind("S=3/2") ``` -------------------------------- ### ITensors.SiteTypes.siteinds - Get Site Indices at Specific Site Source: https://docs.itensor.org/ITensorMPS/stable/MPSandMPO Returns the site Indices of an MPS or MPO at a specific site `j`, with optional filtering. ```APIDOC ## ITensors.SiteTypes.siteinds - Get Site Indices at Specific Site ### Description Return the site Indices found of the MPO or MPS at the site `j` as an IndexSet. Optionally filter prime tags and prime levels with keyword arguments like `plev` and `tags`. ### Method `siteinds(M::Union{MPS, MPO}}, j::Integer; kwargs...) ### Endpoint N/A (This is a library function, not a REST endpoint) ### Parameters #### Path Parameters None #### Query Parameters - **j** (Integer) - The site number to retrieve indices from. - **kwargs** - Optional keyword arguments for filtering indices (e.g., `plev`, `tags`). #### Request Body None ### Request Example ```julia # Assuming M is an MPS/MPO and j is an integer site index # site_indices_at_j = siteinds(M, j) # filtered_indices = siteinds(M, j; plev=0, tags="Site") ``` ### Response #### Success Response (200) - **site_indices** (IndexSet) - An IndexSet containing the site indices at the specified site `j`. #### Response Example ```json { "site_indices": [ "Index(\"d=2, Site; \"1\")", "Index(\"l=1\")" ] } ``` ``` -------------------------------- ### ITensorMPS.linkind - Get Link/Bond Index Source: https://docs.itensor.org/ITensorMPS/stable/MPSandMPO Retrieves the link or bond Index connecting the MPS or MPO tensor on site j to site j+1. ```APIDOC ## ITensorMPS.linkind - Get Link/Bond Index ### Description Get the link or bond Index connecting the MPS or MPO tensor on site `j` to site `j+1`. If there is no link Index, returns `nothing`. ### Method `linkind(M::MPS, j::Integer) `linkind(M::MPO, j::Integer) ### Endpoint N/A (This is a library function, not a REST endpoint) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```julia # Assuming M is an MPS or MPO and j is an integer site index # bond_index = linkind(M, j) ``` ### Response #### Success Response (200) - **link_index** (Index or Nothing) - The link index connecting site `j` and `j+1`, or `nothing` if none exists. #### Response Example ```json { "link_index": "Index(\"l=1\")" } ``` ```json { "link_index": null } ``` ``` -------------------------------- ### Get Truncation Error Cutoff for a Specific Sweep Source: https://docs.itensor.org/ITensorMPS/stable/Sweeps Retrieves the truncation error cutoff setting for a specific sweep `n` from the Sweeps object `sw`. ```julia cutoff(sw::Sweeps, n::Int) ``` -------------------------------- ### Get Element Type of ProjMPO Tensors (Julia) Source: https://docs.itensor.org/ITensorMPS/stable/ProjMPO Deduces and returns the element type (e.g., Float64, ComplexF64) of the ITensors contained within the ProjMPO `P`. ```julia eltype(P::ProjMPO) ``` -------------------------------- ### Extend `op` Function for Custom Operator 'Pup' Source: https://docs.itensor.org/ITensorMPS/stable/examples/Physics Demonstrates extending the ITensor `op` function to recognize a new operator name ('Pup') for a specific site type ('S=1/2'). This involves defining a new method for `ITensors.op` that returns the matrix representation of the operator. ```julia using ITensors, ITensorMPS ITensors.op(::OpName"Pup",::SiteType"S=1/2") = [1 0 0 0] ``` -------------------------------- ### ITensors.SiteTypes.siteind - Get First Site Index (Filtered) Source: https://docs.itensor.org/ITensorMPS/stable/MPSandMPO Returns the first site Index found on the MPS or MPO tensor, with optional filtering by prime level and tags. ```APIDOC ## ITensors.SiteTypes.siteind - Get First Site Index (Filtered) ### Description Return the first site Index found on the MPS or MPO (the first Index unique to the `j`th MPS/MPO tensor). You can choose different filters, like prime level and tags, with the `kwargs`. ### Method `siteind(::typeof(first), M::Union{MPS,MPO}, j::Integer; kwargs...) ### Endpoint N/A (This is a library function, not a REST endpoint) ### Parameters #### Path Parameters None #### Query Parameters - **kwargs** - Optional keyword arguments for filtering indices (e.g., `plev`, `tags`). #### Request Body None ### Request Example ```julia # Assuming M is an MPS/MPO, j is an integer site index, and you want to filter by prime level # first_filtered_index = siteind(first, M, j; plev=0) ``` ### Response #### Success Response (200) - **first_site_index** (Index or Nothing) - The first site index matching the filter, or `nothing`. #### Response Example ```json { "first_site_index": "Index(\"d=2, Site; \"1\")" } ``` ```json { "first_site_index": null } ``` ``` -------------------------------- ### Get All Site Indices of MPO with ITensors.SiteTypes.siteinds Source: https://docs.itensor.org/ITensorMPS/stable/MPSandMPO Returns a Vector of IndexSets containing all the site indices of an MPO. This function is useful for a comprehensive view of the indices associated with an MPO. ```julia siteinds(M::MPO; kwargs...) ``` -------------------------------- ### Build Hamiltonian with OpSum - ITensor Source: https://docs.itensor.org/ITensorMPS/stable/tutorials/DMRG This code constructs the Hamiltonian for the one-dimensional Heisenberg model using ITensor's `OpSum` and `MPO` functionalities. It iterates through nearest neighbors, adding spin-spin interaction terms (Sz*Sz, S+*S-, S-*S+) to an `OpSum` object. Finally, it converts the `OpSum` into a Matrix Product Operator (MPO) tensor network representation. ```julia os = OpSum() for j=1:N-1 os += "Sz",j,"Sz",j+1 os += 1/2,"S+",j,"S-",j+1 os += 1/2,"S-",j,"S+",j+1 end H = MPO(os,sites) ``` -------------------------------- ### Get Maximum Link Dimension using `maxlinkdim` Source: https://docs.itensor.org/ITensorMPS/stable/MPSandMPO Retrieves the maximum link dimension of an MPS or MPO. Returns at least `1`, even if there are no explicit link indices. ```julia using ITensors, ITensorMPS s = siteinds("S=1/2", 3) M = random_mps(s; linkdims=4) max_dim = maxlinkdim(M) println("Maximum link dimension: ", max_dim) ``` -------------------------------- ### Get Minimum MPS Bond Dimension for a Specific Sweep Source: https://docs.itensor.org/ITensorMPS/stable/Sweeps Retrieves the minimum MPS bond dimension allowed for a specific sweep `n` from the Sweeps object `sw`. ```julia mindim(sw::Sweeps, n::Int) ``` -------------------------------- ### Define Custom Operator 'P1' for 'Boson' Site Type with Dimension Source: https://docs.itensor.org/ITensorMPS/stable/examples/Physics Shows how to define a custom operator ('P1') for a 'Boson' site type, explicitly providing the dimension (d) of the local Hilbert space. This is necessary for site types like 'Boson' or 'Qudit' where the dimension is not fixed. ```julia using ITensors, ITensorMPS function ITensors.op(::OpName"P1", ::SiteType"Boson", d::Int) o = zeros(d, d) o[1, 1] = 1 return o end ``` -------------------------------- ### Get Maximum MPS Bond Dimension for a Specific Sweep Source: https://docs.itensor.org/ITensorMPS/stable/Sweeps Retrieves the maximum MPS bond dimension allowed for a specific sweep `n` from the Sweeps object `sw`. ```julia maxdim(sw::Sweeps, n::Int) ``` -------------------------------- ### Create Multiple S=3/2 Indices using ITensor Source: https://docs.itensor.org/ITensorMPS/stable/examples/Physics This code snippet demonstrates how to generate an array of ITensor indices, each representing an S=3/2 site, for a system of size N. It uses the `siteinds` function, which leverages the custom `space` definition for `SiteType"S=3/2"` to set the dimension of each index. This is commonly used when setting up a quantum many-body system in ITensor. ```julia using ITensors, ITensorMPS N = 100 sites = siteinds("S=3/2",N) ``` -------------------------------- ### Get Link Index with ITensorMPS.linkind Source: https://docs.itensor.org/ITensorMPS/stable/MPSandMPO Retrieves the link or bond Index connecting the MPS or MPO tensor on site j to site j+1. Returns `nothing` if there is no link Index. ```julia linkind(M::MPS, j::Integer) linkind(M::MPO, j::Integer) ```