Getting Started
OhMyQSIM is a toy quantum simulator package written in Julia to experiment with different methods and approaches. If you have ideas on how to improve or extend, please get involved. A good place to start is by looking through the issues and adding or trying to address them as appropriate.
Notation
Quantum registers with n-qubits have qubits labeled from 1 to n from left to right as
$| m_1 m_2 m_3 \rangle = |m_1\rangle \otimes |m_2\rangle \otimes |m_3\rangle$
This mens the index of such a state in a state vector is $m_1 2^2 + m_2 2^1 + m_3 2^0$
Basic usage
using OhMyQSIM
# Create a quantum register with 3 qubits and initialise to |000>
qreg = FullStateQuantumRegister{ComplexF64}(3, "000")
# Apply a Pauli x operation to the first qubit
qreg.apply_1_qubit!(qreg, Gates.x, 1)
# Print the register
println(to_str(qreg))
results in
(1.0 + 0.0im|100>)
Basic functions
OhMyQSIM.QuantumRegister
— TypeAbstract type and parent of all quantum register types
OhMyQSIM.FullStateQuantumRegister
— TypeImplementation type for full state quantum register
OhMyQSIM.binary_repr
— Functionbinary_repr(num, N)
Get the binary string representation of a decimal integer.
Examples
julia> println(binary_repr(5, 6))
"000101"
OhMyQSIM.to_str
— Functionto_str(qreg::FullStateQuantumRegister)
Function to convert express fullstate quantum register as a string
Examples
julia> ψ = FullStateQuantumRegister{Int}(3, "000")
julia> ψ.state[end] = 1
julia> to_str(ψ)
"(1|000>) + (1|111>)"
OhMyQSIM.apply_1qubit_full
— Functionapply_1qubit_full(qreg, gate, i)
Apply the 1 qubit gate to qubit i by expanding operator fully
OhMyQSIM.apply_1qubit
— Functionapply_1qubit(qreg, gate, i)
Apply the 1 qubit gate to qubit i
OhMyQSIM.apply_1qubit!
— Functionapply_1qubit!(qreg, gate, i)
Apply the 1 qubit gate to qubit i inplace
OhMyQSIM.decompose_2_qubit_gate
— Functiondecompose_2_qubit_gate(gate; threshold=1e-15)
Decompose a 2 qubit gate into a sum of 1 qubit gates on each qubit
OhMyQSIM.apply_2qubit_full
— Functionapply_2qubit_full(qreg, gate, i, j)
Apply the provided 2 qubit gate to qubits i and j by expanding full operator matrix
OhMyQSIM.swap_2qubits
— Functionswap_2qubits(X)
Given a two qubit operation, switch the order of the qubits
OhMyQSIM.apply_2qubit
— Functionapply_2qubit(qreg, gate, i, j)
Apply the provided 2 qubit gate to qubits i and j
OhMyQSIM.apply_2qubit!
— Functionapply_2qubit!(qreg, gate, i, j)
Apply the provided 2 qubit gate to qubits i and j inplace
OhMyQSIM.measure_probs
— Functionmeasure_probs(qreg)
Get for each bitstring
OhMyQSIM.get_conf
— Functionget_conf(cprobs, num, N)
Given an array of cumulative probabilities of configurations and a random number from [0, 1], return the bitstring it corresponds to
OhMyQSIM.measure
— Functionmeasure(qreg, shots)
Given a quantum register, return a typical set of measurements expected
OhMyQSIM.get_counts
— Functionget_counts(results)
Given a set of measurement results in the form of bitstrings, return the counts of each