Other Operations
Custom gates
MimiqCircuitsBase.GateCustom
— Typestruct GateCustom{N,T} <: AbstractGate{N}
N
qubit gate specified by a $2^N \times 2^N$ matrix with elements of type T
.
Use this to construct your own gates based on unitary matrices. Currently only N=1,2 (M=2,4) are recognised.
MIMIQ uses textbook convention for specifying gates.
One qubit gate matrices are defined in the basis $|0\rangle$, $|1\rangle$ e.g.,
\[\operatorname{Z} = \begin{pmatrix} 1&0\\ 0&-1 \end{pmatrix}\]
Two qubit gate matrices are defined in the basis $|00\rangle$, $|01\rangle$>, $|10\rangle$, $|11\rangle$ where the left-most qubit is the first to appear in the target list e.g.,
\[\operatorname{CNOT} = \begin{pmatrix} 1&0&0&0\\ 0&1&0&0\\ 0&0&0&1\\ 0&0&1&0 \end{pmatrix}\]
julia> CNOT = [1 0 0 0; 0 1 0 0; 0 0 0 1; 0 0 1 0]
4×4 Matrix{Int64}:
1 0 0 0
0 1 0 0
0 0 0 1
0 0 1 0
julia> # CNOT gate with control on q1 and target on q2
julia> Instruction(GateCustom(CNOT), 1, 2)
GateCustom([1 0 0 0; 0 1 0 0; 0 0 0 1; 0 0 1 0]) @ q1, q2
# Examples
jldoctest julia> g = GateCustom([1 0; 0 1]) Custom([1.0 0.0; 0.0 1.0])
julia> push!(Circuit(), g, 1) 1-qubit circuit with 1 instructions: └── Custom([1.0 0.0; 0.0 1.0]) @ q1 ```
Gate definitions
MimiqCircuitsBase.GateCall
— TypeGateCall(decl, args...)
Gate corresponding to a call to a GateDecl
definition.
It is created by calling a GateDecl
with the proper number of arguments.
Examples
julia> decl = @gatedecl ansatz(θ) = begin
insts = Instruction[]
push!(insts, Instruction(GateX(), 1))
push!(insts, Instruction(GateRX(θ), 2))
return insts
end;
julia> @variables λ;
julia> decl(λ)
ansatz(λ)
See also
MimiqCircuitsBase.GateDecl
— TypeGateDecl(name, args, instructions)
Define a new gate of given name, arguments and instructions.
Examples
A simple gate declaration, via the @gatedecl
macro:
julia> decl = @gatedecl ansatz(θ) = begin
insts = Instruction[]
push!(insts, Instruction(GateX(), 1))
push!(insts, Instruction(GateRX(θ), 2))
return insts
end
gate ansatz(θ) =
├── X @ q[1]
└── RX(θ) @ q[2]
julia> @variables λ;
julia> decompose(decl(λ))
2-qubit circuit with 2 instructions:
├── X @ q[1]
└── RX(λ) @ q[2]
See also
Non-unitary operations
MimiqCircuitsBase.Reset
— TypeReset()
Quantum operation that resets the status of one qubit to the $\ket{0}$ state.
Examples
julia> Reset()
Reset
julia> c = push!(Circuit(), Reset, 1)
1-qubit circuit with 1 instructions:
└── Reset @ q[1]
julia> push!(c, Reset(), 3)
3-qubit circuit with 2 instructions:
├── Reset @ q[1]
└── Reset @ q[3]
MimiqCircuitsBase.Measure
— TypeMeasure()
Single qubit measurement operation in the computational basis
The operation projects the quantum states and stores the result of such measurement is stored in a classical register.
Measure
is non-reversible.
Examples
julia> Measure()
Measure
julia> c = push!(Circuit(), Measure, 1, 1)
1-qubit circuit with 1 instructions:
└── Measure @ q[1], c[1]
julia> push!(c, Measure(), 3, 4)
3-qubit circuit with 2 instructions:
├── Measure @ q[1], c[1]
└── Measure @ q[3], c[4]
No-ops
MimiqCircuitsBase.Barrier
— TypeBarrier(numqubits)
No-op operation that does not affect the quantum state or the execution of a circuit, but prevents compression or optimization across it.
Examples
julia> Barrier(1)
Barrier
julia> Barrier(2)
Barrier
julia> c = push!(Circuit(), Barrier(1), 1)
1-qubit circuit with 1 instructions:
└── Barrier @ q[1]
julia> push!(c, Barrier(1), 1:3)
3-qubit circuit with 4 instructions:
├── Barrier @ q[1]
├── Barrier @ q[1]
├── Barrier @ q[2]
└── Barrier @ q[3]
julia> push!(c, Barrier(3), 1,2,3)
3-qubit circuit with 5 instructions:
├── Barrier @ q[1]
├── Barrier @ q[1]
├── Barrier @ q[2]
├── Barrier @ q[3]
└── Barrier @ q[1:3]