Custom gates
BraketSimulator.jl
defines some custom gates to extend what Braket.jl
provides.
BraketSimulator.MultiRZ
— TypeMultiRz(angle)
Multi-qubit Z-rotation gate. The 2-qubit version is equivalent to the ZZ
gate, and the single-qubit version is equivalent to the Rz
gate.
BraketSimulator.DoubleExcitation
— TypeDoubleExcitation(ϕ)
Generate the matrix representation of the DoubleExcitation gate.
This gate performs an SO(2) rotation in the subspace ${|1100\rangle, |0011\rangle}$, transforming the states as follows:
\[|0011\rangle & \rightarrow \cos\left(\frac{\phi}{2}\right)|0011\rangle + \sin\left(\frac{\phi}{2}\right)|1100\rangle \ |1100\rangle & \rightarrow \cos\left(\frac{\phi}{2}\right)|1100\rangle - \sin\left(\frac{\phi}{2}\right)|0011\rangle\]
Examples
julia> using BraketSimulator
julia> ϕ = 3.56;
julia> gate_matrix = BraketSimulator.DoubleExcitation(ϕ);
julia> m = BraketSimulator.matrix_rep(gate_matrix);
julia> eq1 = m * [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
julia> eq2 = m * [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0];
julia> eq1 == [0, 0, 0, cos(ϕ/2), 0, 0, 0, 0, 0, 0, 0, 0, sin(ϕ/2), 0, 0, 0] == true;
julia> eq2 == [0, 0, 0, -sin(ϕ/2), 0, 0, 0, 0, 0, 0, 0, 0, cos(ϕ/2), 0, 0, 0] == true;
BraketSimulator.DoubleExcitationMinus
— TypeDoubleExcitationMinus(ϕ)
Generate the matrix representation of the DoubleExcitationMinus gate.
This gate performs an SO(2) rotation in the subspace ${|1100\rangle, |0011\rangle}$ with a phase-shift on other states:
\[|0011\rangle & \rightarrow \cos\left(\frac{\phi}{2}\right)|0011\rangle - \sin\left(\frac{\phi}{2}\right)|1100\rangle \ |1100\rangle & \rightarrow \cos\left(\frac{\phi}{2}\right)|1100\rangle + \sin\left(\frac{\phi}{2}\right)|0011\rangle \ |x\rangle & \rightarrow e^{-\frac{i\phi}{2}}|x\rangle \quad \text{for all other basis states } |x\rangle\]
Examples
julia> using BraketSimulator
julia> ϕ = 3.56;
julia> gate_matrix = BraketSimulator.DoubleExcitationMinus(ϕ);
julia> m = BraketSimulator.matrix_rep(gate_matrix);
julia> eq1 = m * [1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1];
julia> eq2 = m * [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1];
julia> eq1 == [exp(-im*ϕ/2), 0, 0, cos(ϕ/2), 0, 0, 0, 0, 0, 0, 0, 0, sin(ϕ/2), 0, 0, exp(-im*ϕ/2)] == true;
julia> eq2 == [exp(-im*ϕ/2), 0, 0, -sin(ϕ/2), 0, 0, 0, 0, 0, 0, 0, 0, cos(ϕ/2), 0, 0, exp(-im*ϕ/2)] == true;
BraketSimulator.DoubleExcitationPlus
— TypeDoubleExcitationPlus(ϕ)
Generate the matrix representation of the DoubleExcitationPlus gate.
This gate performs an SO(2) rotation in the subspace ${|1100\rangle, |0011\rangle}$ with a phase-shift on other states:
\[|0011\rangle & \rightarrow \cos\left(\frac{\phi}{2}\right)|0011\rangle - \sin\left(\frac{\phi}{2}\right)|1100\rangle \ |1100\rangle & \rightarrow \cos\left(\frac{\phi}{2}\right)|1100\rangle + \sin\left(\frac{\phi}{2}\right)|0011\rangle \ |x\rangle & \rightarrow e^{\frac{i\phi}{2}}|x\rangle \quad \text{for all other basis states } |x\rangle\]
Examples
julia> using BraketSimulator
julia> ϕ = 3.56;
julia> gate_matrix = BraketSimulator.DoubleExcitationPlus(ϕ);
julia> m = BraketSimulator.matrix_rep(gate_matrix);
julia> eq1 = m * [1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1];
julia> eq2 = m * [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1];
julia> eq1 == [exp(im*ϕ/2), 0, 0, cos(ϕ/2), 0, 0, 0, 0, 0, 0, 0, 0, sin(ϕ/2), 0, 0, exp(im*ϕ/2)] == true;
julia> eq2 == [exp(im*ϕ/2), 0, 0, -sin(ϕ/2), 0, 0, 0, 0, 0, 0, 0, 0, cos(ϕ/2), 0, 0, exp(im*ϕ/2)] == true;
BraketSimulator.SingleExcitation
— TypeSingleExcitation(ϕ)
Generate the matrix representation of the SingleExcitation gate.
This gate performs a rotation in the subspace ${|01\rangle, |10\rangle}$.
Examples
julia> using BraketSimulator
julia> ϕ = 3.56;
julia> gate_matrix = BraketSimulator.SingleExcitation(ϕ);
julia> m = BraketSimulator.matrix_rep(gate_matrix);
julia> eq1 = m * [0, 1, 0, 0];
julia> eq2 = m * [0, 0, 1, 0];
julia> eq1 == [0, cos(ϕ/2), - sin(ϕ/2), 0] == true;
julia> eq2 == [0, sin(ϕ/2), cos(ϕ/2), 0] == true;
BraketSimulator.SingleExcitationMinus
— TypeSingleExcitationMinus(ϕ)
Generate the matrix representation of the SingleExcitationMinus gate.
This gate performs a rotation in the subspace ${|01\rangle, |10\rangle}$ with a phase-shift.
Examples
julia> using BraketSimulator
julia> ϕ = 3.56;
julia> gate_matrix = BraketSimulator.SingleExcitationMinus(ϕ);
julia> m = BraketSimulator.matrix_rep(gate_matrix);
julia> eq1 = m * [1, 1, 0, 0];
julia> eq2 = m * [1, 0, 1, 0];
julia> eq1 == [exp(-im*ϕ/2), cos(ϕ/2), - sin(ϕ/2), 0] == true;
julia> eq2 == [exp(-im*ϕ/2), sin(ϕ/2), cos(ϕ/2), 0] == true;
BraketSimulator.SingleExcitationPlus
— TypeSingleExcitationPlus(ϕ)
Generate the matrix representation of the SingleExcitationPlus gate.
This gate performs a rotation in the subspace ${|01\rangle, |10\rangle}$ with a phase-shift.
Examples
julia> using BraketSimulator
julia> ϕ = 3.56;
julia> gate_matrix = BraketSimulator.SingleExcitationPlus(ϕ);
julia> m = BraketSimulator.matrix_rep(gate_matrix);
julia> eq1 = m * [1, 1, 0, 0];
julia> eq2 = m * [1, 0, 1, 0];
julia> eq1 == [exp(im*ϕ/2), cos(ϕ/2), - sin(ϕ/2), 0] == true;
julia> eq2 == [exp(im*ϕ/2), sin(ϕ/2), cos(ϕ/2), 0] == true;
BraketSimulator.FermionicSWAP
— TypeFermionicSWAP(ϕ)
Generate the matrix representation of the FermionicSWAP gate.
This gate performs a rotation in adjacent fermionic modes under the Jordan-Wigner mapping, transforming states as follows:
\[|00\rangle & \rightarrow |00\rangle \ |01\rangle & \rightarrow e^{\frac{i\phi}{2}}\cos\left(\frac{\phi}{2}\right)|01\rangle - ie^{\frac{i\phi}{2}}\sin\left(\frac{\phi}{2}\right)|10\rangle \ |10\rangle & \rightarrow -ie^{\frac{i\phi}{2}}\sin\left(\frac{\phi}{2}\right)|01\rangle + e^{\frac{i\phi}{2}}\cos\left(\frac{\phi}{2}\right)|10\rangle \ |11\rangle & \rightarrow e^{i\phi}|11\rangle\]
Examples
julia> using BraketSimulator
julia> ϕ = 3.56;
julia> gate_matrix = BraketSimulator.FermionicSWAP(ϕ);
julia> m = BraketSimulator.matrix_rep(gate_matrix);
julia> eq1 = m * [0, 0, 0, 0];
julia> eq2 = m * [0, 1, 0, 0];
julia> eq3 = m * [0, 0, 1, 0];
julia> eq4 = m * [0, 0, 0, 1];
julia> eq1 == [0, 0, 0, 0] == true;
julia> eq2 == [0, exp(im*ϕ/2.0)*cos(ϕ / 2.0), - im*exp(im*ϕ/2.0)*sin(ϕ/2.0), 0] == true;
julia> eq3 == [0, - im*exp(im*ϕ/2.0)*sin(ϕ/2.0), exp(im*ϕ/2.0)*cos(ϕ/2.0), 0] == true;
julia> eq4 == [0, 0, 0, exp(im * ϕ)] == true;