Quantum Circuit Utils
u = ket(1, 2); # |0⟩
d = ket(2, 2); # |1⟩
u, d(ComplexF64[1.0 + 0.0im, 0.0 + 0.0im], ComplexF64[0.0 + 0.0im, 1.0 + 0.0im])State Vectors Utility
QuantumCircuits.random_statevector — Function
random_statevector(n::Int) :: Vector{ComplexF64}Generate a random state vector of length 2^n.
Arguments
n::Int: The number of qubits.
Returns
v::Vector{ComplexF64}: The random state vector.
QuantumCircuits.is_valid_statevector — Function
is_valid_statevector(v::Vector{ComplexF64}) :: BoolCheck if the given vector v is a valid state vector.
A valid state vector is a vector of complex numbers whose Euclidean norm is approximately equal to 1.
Arguments
v::Vector{ComplexF64}: The vector to be checked.
Returns
trueif the vector is a valid state vector,falseotherwise.
QuantumCircuits.zero_state — Function
zero_state(n::Int) :: Vector{ComplexF64}Initialize the state vector for a quantum circuit with n qubits.
Arguments
n::Int: The number of qubits in the quantum circuit.
Returns
v::Vector{ComplexF64}: The initialized state vector.
Quantum Information Quantities
Fidelity
The fidelity between two states is defined as the square of the overlap between the two states.
\[F(\psi, \phi) = |\langle \psi | \phi \rangle|^2\]
QuantumCircuits.fidelity — Function
fidelity(v1::Vector{ComplexF64}, v2::Vector{ComplexF64}) :: Float64Compute the fidelity between two complex vectors v1 and v2.
The fidelity is defined as the squared absolute value of the dot product between v1 and v2.
Arguments
v1::Vector{ComplexF64}: The first complex vector.v2::Vector{ComplexF64}: The second complex vector.
Returns
Float64: The fidelity betweenv1andv2.
fidelity(u, d)0.0The fidelity function is defined in the QuantumInformation module as well, so you may need to use the full path to the function.
QuantumCircuits.fidelity(u, d)Probability
The probability of measuring a state in a given basis is the square of the amplitude of the state in that basis.
\[P(\psi, \Pi) = |\langle \psi | \Pi | \psi \rangle|\]
QuantumCircuits.prob — Function
prob(state::Vector{ComplexF64}, Π::Matrix{ComplexF64})::Float64Compute the probability of measuring a quantum state state given the measurement operator Π.
Arguments
state::Vector{ComplexF64}: The quantum state vector.Π::Matrix{ComplexF64}: The measurement operator.
Returns
Float64: The probability of measuring the state.
Pi = u * u';
prob(u, Pi)1.0Measurement
QuantumCircuits.projective_measurement_operator — Function
projective_measurement_operator(n::Int, basis::Char, index::Int)::Matrix{ComplexF64}Constructs the projective measurement operator for a quantum circuit.
Arguments
n::Int: The number of qubits in the quantum circuit.basis::Char: The measurement basis. Must be either 'z' or 'x'.index::Int: The index of the qubit to be measured.
Returns
A matrix representing the projective measurement operator.
QuantumCircuits.post_measurement_state — Function
post_measurement_state(state::Vector{ComplexF64}, Π::Matrix{ComplexF64})::Vector{ComplexF64}Post-processes the state vector after a measurement is performed.
Arguments
state::Vector{ComplexF64}: The input state vector.Π::Matrix{ComplexF64}: The measurement operator.
Returns
Vector{ComplexF64}: The post-measurement state vector.
Throws
ArgumentError: If the probability of getting the measurement outcome is zero.