Library reference
ITensorMPS.MPOQuantumCircuitSimulator.GateNameQuantumCircuitSimulator.QuantumCircuitQuantumCircuitSimulator.QuantumCircuitQuantumCircuitSimulator.QuantumCircuitQuantumCircuitSimulator.SPLNoiseModelQuantumCircuitSimulator.cropQuantumCircuitSimulator.definitionQuantumCircuitSimulator.freesitesQuantumCircuitSimulator.freesitesQuantumCircuitSimulator.gateQuantumCircuitSimulator.gateQuantumCircuitSimulator.gateQuantumCircuitSimulator.gateQuantumCircuitSimulator.gatelayersQuantumCircuitSimulator.gatesQuantumCircuitSimulator.gatesQuantumCircuitSimulator.instructionsitesQuantumCircuitSimulator.inversenoiselayerQuantumCircuitSimulator.inversenoiselayerQuantumCircuitSimulator.lastblockinglayerQuantumCircuitSimulator.layers_mpoQuantumCircuitSimulator.noise_ptm_coefficientsQuantumCircuitSimulator.noiselayerQuantumCircuitSimulator.noiselayerQuantumCircuitSimulator.occupiedsitesQuantumCircuitSimulator.qbitsitesQuantumCircuitSimulator.relevantpaulistringsQuantumCircuitSimulator.samplepaulistrings
ITensorMPS.MPO — Method
MPO(sites::Vector{<:Index}, noisemodel::SPLNoiseModel; maxbonddim)Return the MPO form of a layer of the noise map generated by the parameter sets described in the sparse Pauli-Lindblad model object model. Optionally truncate the resulting MPO to a bond dimension equal to maxbonddim.
QuantumCircuitSimulator.GateName — Method
GateName is a parameterized type which allows making strings into Julia types for the purpose of representing gate names. The main use of GateName is overloading the gate method which generates operators for Qubit and vQubit sites.
To make a GateName type, you can use the string macro notation: GateName"MyTag". To make an GateName value or object, you can use the notation: GateName("mygate").
QuantumCircuitSimulator.QuantumCircuit — Type
QuantumCircuitA QuantumCircuit is an aggregate type that stores the qbit array of the circuit and the sequence of gates, or instructions, arranged in layers.
QuantumCircuitSimulator.QuantumCircuit — Method
QuantumCircuit(sites)Return an empty circuit, in which the qbit array is defined but which contains no gates.
QuantumCircuitSimulator.QuantumCircuit — Method
QuantumCircuit(code::OpenQASM.Types.MainProgram; kwargs...)
QuantumCircuit(code::AbstractString; kwargs...)Parse the circuit defined in code (either a string or an already parsed OpenQASM program) as a QuantumCircuit object, structuring the sequence of gates in layer. The gates are added to the layers in a way that should resemble the "ASAP" policy by Qiskit.
Keyword arguments
operator_picture: iffalse(default) then the circuit is interpreted as a sequence of gates to be applied to a pure state; if it istrueinstead it will be a sequence of gates to be applied to mixed states (in the Schrödinger picture) or to observables (in the Heisenberg picture).warn_on_gate_redefinitioniffalse(default), ignore the "Method overwritten" warnings that the Julia compiler might print whenever a gate definition overwrites an existing one.
QuantumCircuitSimulator.SPLNoiseModel — Type
SPLNoiseModelA sparse Pauli-Lindblad noise model, represented by a dictionary of generators and a list of qbits it acts on.
QuantumCircuitSimulator.crop — Method
crop(model::SPLNoiseModel, range)Return a subset of model keeping only the Pauli strings whose non-trivial factors lie completely within range.
QuantumCircuitSimulator.definition — Method
definition(declaration::OpenQASM.Types.Gate, st::SiteType)Return a string containing Julia code necessary to add a gate method with the given name and the site type st using the instructions contained in the OpenQASM declaration.
Example
julia> str = "OPENQASM 2.0;
qreg q[2];
gate test(a, b, c) q0, q1 {
h q1;
cx q0, q1;
rz(a) q1;
u2(b, c) q0;
y q1;
}"
julia> g = OpenQASM.parse(str);
julia> print(QuantumCircuitSimulator.definition(g.prog[2], SiteType("Qubit")))
function QuantumCircuitSimulator.gate(::GateName"test", ::SiteType"Qubit", q0::Index, q1::Index; cargs)
a::Real = cargs[1]
b::Real = cargs[2]
c::Real = cargs[3]
compose(gate("y", q1), compose(gate("u2", q0; cargs=(b,c)), compose(gate("rz", q1; cargs=(a)), compose(gate("cx", q0, q1), gate("h", q1)))))
endQuantumCircuitSimulator.freesites — Method
freesites(circ::QuantumCircuit, gl::GateLayer)Return a list of the sites in the circuit circ with no gates from the gl layer acting upon them.
QuantumCircuitSimulator.freesites — Method
freesites(sites::Vector{<:ITensor.Index}, gl::GateLayer)Return a list of the sites in sites that are not acted upon by any gate from the gl layer.
QuantumCircuitSimulator.gate — Method
gate(X::AbstractArray, s::Index...)
gate(M::Matrix, s::Index...)Given a matrix M and a set of indices s, t, ... return a gate ITensor with matrix elements given by M and indices s, s', t, t'.
Examples
julia> s = siteind("Qubit")
(dim=2|id=575|"Qubit,Site")
julia> g = gate([1/2 0; 0 -1/2], s)
ITensor ord=2 (dim=2|id=575|"Qubit,Site")' (dim=2|id=575|"Qubit,Site")
NDTensors.Dense{Float64, Vector{Float64}}
julia> @show g
g = ITensor ord=2
Dim 1: (dim=2|id=575|"Qubit,Site")'
Dim 2: (dim=2|id=575|"Qubit,Site")
NDTensors.Dense{Float64, Vector{Float64}}
2×2
0.5 0.0
0.0 -0.5
ITensor ord=2 (dim=2|id=575|"Qubit,Site")' (dim=2|id=575|"Qubit,Site")
NDTensors.Dense{Float64, Vector{Float64}}QuantumCircuitSimulator.gate — Method
gate(name::AbstractString, s::Index...; kwargs...)Return an ITensor corresponding to the gate named name for the Index s. The operator is constructed by calling an overload of the gate method which takes a SiteType argument that corresponds to one of the tags of the Index s and an GateName"name" argument that corresponds to the input gate name. If the gate requires numerical parameters (a.k.a. "classical arguments") too, they must be provided within a keyword argument named cargs.
Example
s = siteinds("Qubit", 2)
z = gate("z", s[1])
u3 = gate("u3", s[1]; cargs=(0, pi/4, 2))
cp = gate("cp", s[1], s[2]; cargs=(pi/2))QuantumCircuitSimulator.gate — Method
gate(gatename, s::Vector{<:Index}, ns::Vararg{Integer}; kwargs...)Return an ITensor corresponding to the gate named gatename on sites s[n] for each n in ns.
Example
s = siteinds("Qubit", 4)
g2 = gate("x", s, 2)
g13 = gate("cnot", s, 1, 3)QuantumCircuitSimulator.gate — Method
gate(gatename, s::Vector{<:Index}, ns::NTuple{N,Integer}; kwargs...)Return an ITensor corresponding to the gate named gatename on sites s[n] for each n in the tuple ns.
Example
s = siteinds("Qubit", 4)
g2 = gate("x", s, 2)
g13 = gate("cnot", s, (1, 3))QuantumCircuitSimulator.gatelayers — Method
gatelayers(gates::Vector{ITensor})Return a list of MPOs, each one representing a layer of the circuit. A layer is created multiplying together as many adjacent gates as possible, i.e. the construction of the MPO ends as soon as the next gate in line acts on a qbit which is already acted on by the gates already in the MPO. This way, all gates in a layer commute with each other and can be executed in any order.
QuantumCircuitSimulator.gates — Method
gates(code::OpenQASM.Types.MainProgram, st::AbstractString; warn_on_gate_redefinition)Create a list of gates (ITensor operators) as parsed from the given OpenQASM code, returning a tuple (s, ops) where:
sis a vector of ITensor indices of SiteTypest(an index for each qbit declared incode),opsis a list of ITensor operators, one for each gate, in the appearance order incode.
Example
julia> code = OpenQASM.parse("OPENQASM 2.0; qreg a[2]; cx a[0], a[1];");
julia> s, g = gates(code, "Qubit"; warn_on_gate_redefinition=false);
julia> s
2-element Vector{ITensors.Index{Int64}}:
(dim=2|id=680|"Qubit,Site,a,n=1")
(dim=2|id=758|"Qubit,Site,a,n=2")
julia> g[1]
ITensor ord=4 (dim=2|id=758|"Qubit,Site,a,n=2")' (dim=2|id=680|"Qubit,Site,a,n=1")' (dim=2|id=758|"Qubit,Site,a,n=2") (dim=2|id=680|"Qubit,Site,a,n=1")
NDTensors.Dense{Float64, Vector{Float64}}QuantumCircuitSimulator.gates — Method
gates(code::OpenQASM.Types.MainProgram, sites::Vector{<:Index})Return a list of gates (ITensor operators) as parsed from the given OpenQASM code, building the operators on the already existing Index objects in sites. The given sites are checked to ensure they are compatible to the ones that would be generated from code.
QuantumCircuitSimulator.instructionsites — Method
instructionsites(instr::OpenQASM.Types.Instruction, sites::Vector{<:Index})
instructionsites(instr::OpenQASM.Types.Barrier, sites::Vector{<:Index})Return the indices within sites on which the instruction or barrier instr acts.
QuantumCircuitSimulator.inversenoiselayer — Method
inversenoiselayer(
sites::Vector{<:Index}, ptm_generator_vec, ptm_generator_mat; maxbonddim=nothing
)Return the MPO form of the inverse of the noise map generated by the parameter sets ptm_generator_vec and ptm_generator_mat.
References
- [1] S. Filippov, M. Leahy, M. A. C. Rossi and G. García-Pérez, arXiv 2307.11740 (2023)
QuantumCircuitSimulator.inversenoiselayer — Method
inversenoiselayer(sites::Vector{<:Index}, model::SPLNoiseModel; maxbonddim=nothing)Return the MPO form of the inverse of the noise map generated by the parameter sets described in the sparse Pauli-Lindblad model object model.
QuantumCircuitSimulator.lastblockinglayer — Method
lastblockinglayer(circ::QuantumCircuit, sites)Return the index of the layer that something (a gate, or a barrier) acting on sites cannot slide past: it may be placed in any layer after this one, but not in this one or any earlier one. Return 0 if it could be placed in the very first layer (in particular, if circ is empty).
QuantumCircuitSimulator.layers_mpo — Method
layers_mpo(circ; progress=false)Return a list of MPOs, one for each layer of the circuit circ. Optionally display a progress bar by setting progress to true.
QuantumCircuitSimulator.noise_ptm_coefficients — Method
noise_ptm_coefficients(ptm_generator_vec, ptm_generator_mat)Return the parameters of the noise model in the sparse Pauli-Lindblad model from the given set of coefficients ptm_generator_vec and ptm_generator_mat, respectively a set of $N$ 3-element vectors and a set of $N$ 3x3 matrices, where $N$ represents the number of qbits in the circuit.
QuantumCircuitSimulator.noiselayer — Method
noiselayer(
sites::Vector{<:Index},
indices,
ptm_generator_vec,
ptm_generator_mat;
maxbonddim=nothing
)Return the MPO form of a layer of the noise map generated by the parameter sets ptm_generator_vec and ptm_generator_mat, acting on the indices sites[i] for all i in indices. The MPO will be defined on all sites (as the identity on those sites i which are not in indices). Optionally, truncate the resulting MPO to a bond dimension equal to maxbonddim.
References
- [1] S. Filippov, M. Leahy, M. A. C. Rossi and G. García-Pérez, arXiv 2307.11740 (2023)
QuantumCircuitSimulator.noiselayer — Method
noiselayer(sites::Vector{<:Index}, model::SPLNoiseModel; maxbonddim=nothing)Return the MPO form of a layer of the noise map generated by the parameter sets described in the sparse Pauli-Lindblad model object model. Optionally truncate the resulting MPO to a bond dimension equal to maxbonddim.
QuantumCircuitSimulator.occupiedsites — Method
occupiedsites(gl::GateLayer)Return the indices within sites on which the gates in the gl layer act.
QuantumCircuitSimulator.qbitsites — Method
qbitsites(code::OpenQASM.Types.MainProgram, st::AbstractString)Return the ITensor site indices, of SiteType st, associated to the quantum registers defined in the given code.
Example
julia> code = OpenQASM.parse("OPENQASM 2.0; qreg a[3]; qreg b[2];");
julia> qbitsites(code, "Qubit")
5-element Vector{ITensors.Index{Int64}}:
(dim=2|id=187|"Qubit,Site,a[0]")
(dim=2|id=539|"Qubit,Site,a[1]")
(dim=2|id=321|"Qubit,Site,a[2]")
(dim=2|id=981|"Qubit,Site,b[0]")
(dim=2|id=596|"Qubit,Site,b[2]")QuantumCircuitSimulator.relevantpaulistrings — Method
relevantpaulistrings(v::MPS; nsamples, maxn, cutoff, imag_atol=1e-10, progress=false)Sample at most nsamples Pauli strings from the MPS v (which is assumed to represent an observable in the PTM basis) and return a list of tuples of the form (ps, coeff, freq) where:
psis a Pauli string (a PauliString object)coeffis its coefficient withinvfreqis the frequency with which it was sampled (it should equal|coeff|^2in the limit wherensamplesgoes to infinity).
The list is shown from the most to least relevant component, i.e. highest to lowest modulus of the coefficient. It can be cutoff after a certain maximum number of strings (maxn), or below a set frequency (cutoff).
If progress is true, a progress bar is displayed while sampling.
QuantumCircuitSimulator.samplepaulistrings — Method
samplepaulistrings(v::MPS, nsamples::Integer; progress=false)Sample nsamples Pauli strings from v and compute their overlap with the MPS. Return a pair ps, overlaps where overlaps[k] is the coefficient of the ps[k] component of v: this means that if we write v as a linear combination of Pauli strings $v = ∑_k c_kσ_k$ then overlaps[k] is the coefficient $c_k$.
Note that the MPS of a Pauli string is not normalized in the Hilbert-Schmidt inner product $⟨A,B⟩ = \tr(\adj{A} B)$: the norm of a Pauli string of length N is 2^(N/2).
If progress is true, a progress bar is displayed while sampling.