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_statevectorFunction
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.
source
QuantumCircuits.is_valid_statevectorFunction
is_valid_statevector(v::Vector{ComplexF64}) :: Bool

Check 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

  • true if the vector is a valid state vector, false otherwise.
source
QuantumCircuits.zero_stateFunction
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.
source

Quantum Information Quantities

Fidelity

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.fidelityFunction
fidelity(v1::Vector{ComplexF64}, v2::Vector{ComplexF64}) :: Float64

Compute 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 between v1 and v2.
source
fidelity(u, d)
0.0
Fidelity over loaded

The 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

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.probFunction
prob(state::Vector{ComplexF64}, Π::Matrix{ComplexF64})::Float64

Compute 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.
source
Pi = u * u';
prob(u, Pi)
1.0

Measurement

QuantumCircuits.projective_measurement_operatorFunction
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.

source
QuantumCircuits.post_measurement_stateFunction
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.
source