GateMap
Given many algorithms will have repeated use of specific custom or parametric gates, it can be useful to store these for later use. In addition, to allow use of the GateSymbol
type to represent numeric matrices, we require a location to provide this mapping. This module operates as this cache, and allows sotrage for gates generated during the circuit creation.
The GateMap.gates
dictionary defines a mapping between GateSymbols
& Functions
to a given generator Function
. To aid with ease of translation and extensibility, additional platforms may define the base gate mappings here to generator the required out structures for a given target platform.
For our use as a framework for creating tensor network simulations, we map the required GateSymbols
and Functions
to produce StaticArrays
types for numerical representation.
Utility and types
QXZoo.GateMap.gates
— ConstantModule gate cache
Since many different circuits may use the same gates, keeping a module-global cache makes sense to avoid recreating them. Each subcircuit can have a subset of the global cache's gates.
QXZoo.GateMap.init_cache
— Methodinit_cache()
Initialise the cache for default gates used in circuit generation. Modules generating gates not stored here should cache them for use by other circuits.
QXZoo.GateMap.cache_gate!
— Methodcache_gate!(label::GateOps.AGateSymbol, mat::Matrix{<:Number})
Adds a mapping between label=>mat for fast retrieval of gates in circuit generation.
Examples
julia> QXZoo.GateMap.cache_gate!(QXZoo.GateOps.GateSymbol(:mygate), ()->[ 1 0; 0 1])
QXZoo.GateMap.clear_cache
— Methodclear_cache()
Empty the stored gates from the cache.
QXZoo.GateMap.create_gate_1q
— Methodcreate_gate_1q(gate_label::String, gen_func::Function)
Creates a new user-defined gate, caches the generating function, and returns the GateOps.GateSymbol key for use in a circuit.
Examples
QXZoo.GateMap.create_gate_1q
— Methodcreate_gate_1q(gate_label::String, mat::Array{Complex{Float64},2})
Creates a new user-defined gate, caches the generating matrix, and returns the GateOps.GateSymbol key for use in a circuit. Matrix is converted to 2x2 StaticArrays SMatrix internally.
Examples
QXZoo.GateMap.create_gate_2q
— Methodcreate_gate_2q(gate_label::String, gen_func::Function)
Creates a new user-defined gate, caches the generating function, and returns the GateOps.GateSymbol key for use in a circuit.
Examples
QXZoo.GateMap.create_gate_2q
— Methodcreate_gate_2q(gate_label::String, mat::Array{Complex{Float64},2})
Creates a new user-defined gate, caches the generating matrix, and returns the GateOps.GateSymbol key for use in a circuit. Matrix is converted to 2x2 StaticArrays SMatrix internally.
Examples
Gate generator functions
QXZoo.GateMap.p00
— Methodp00()::SArray{Tuple{2,2},Complex{Float64},2,4}
Function which generates the |0><0| projector gate.
Examples
julia> QXZoo.GateMap.p00()
2×2 StaticArrays.SArray{Tuple{2,2},Complex{Float64},2,4} with indices SOneTo(2)×SOneTo(2):
1.0+0.0im 0.0+0.0im
0.0+0.0im 0.0+0.0im
QXZoo.GateMap.p01
— Methodp01()::SArray{Tuple{2,2},Complex{Float64},2,4}
Function which generates the |0><1| projector gate.
Examples
julia> QXZoo.GateMap.p01()
2×2 StaticArrays.SArray{Tuple{2,2},Complex{Float64},2,4} with indices SOneTo(2)×SOneTo(2):
0.0+0.0im 1.0+0.0im
0.0+0.0im 0.0+0.0im
QXZoo.GateMap.p10
— Methodp10()::SArray{Tuple{2,2},Complex{Float64},2,4}
Function which generates the |1><0| projector gate.
Examples
julia> QXZoo.GateMap.p10()
2×2 StaticArrays.SArray{Tuple{2,2},Complex{Float64},2,4} with indices SOneTo(2)×SOneTo(2):
0.0+0.0im 0.0+0.0im
1.0+0.0im 0.0+0.0im
QXZoo.GateMap.p11
— Methodp11()::SArray{Tuple{2,2},Complex{Float64},2,4}
Function which generates the |1><1| projector gate.
Examples
julia> QXZoo.GateMap.p11()
2×2 StaticArrays.SArray{Tuple{2,2},Complex{Float64},2,4} with indices SOneTo(2)×SOneTo(2):
0.0+0.0im 0.0+0.0im
0.0+0.0im 1.0+0.0im
QXZoo.GateMap.x
— Methodx()::SArray{Tuple{2,2},Complex{Float64},2,4}
Function which generates the Pauli-X gate.
Examples
julia> QXZoo.GateMap.x()
2×2 StaticArrays.SArray{Tuple{2,2},Complex{Float64},2,4} with indices SOneTo(2)×SOneTo(2):
0.0+0.0im 1.0+0.0im
1.0+0.0im 0.0+0.0im
QXZoo.GateMap.y
— Methody()::SArray{Tuple{2,2},Complex{Float64},2,4}
Function which generates the Pauli-Y gate.
Examples
julia> QXZoo.GateMap.y()
2×2 StaticArrays.SArray{Tuple{2,2},Complex{Float64},2,4} with indices SOneTo(2)×SOneTo(2):
0.0+0.0im -0.0-1.0im
0.0+1.0im 0.0+0.0im
QXZoo.GateMap.z
— Methodz()::SArray{Tuple{2,2},Complex{Float64},2,4}
Function which generates the Pauli-Z gate.
Examples
julia> QXZoo.GateMap.z()
2×2 StaticArrays.SArray{Tuple{2,2},Complex{Float64},2,4} with indices SOneTo(2)×SOneTo(2):
1.0+0.0im 0.0+0.0im
0.0+0.0im -1.0+0.0im
QXZoo.GateMap.h
— Methodh()::SArray{Tuple{2,2},Complex{Float64},2,4}
Function which generates the Hadamard gate.
Examples
julia> QXZoo.GateMap.h()
2×2 StaticArrays.SArray{Tuple{2,2},Complex{Float64},2,4} with indices SOneTo(2)×SOneTo(2):
0.707107+0.0im 0.707107+0.0im
0.707107+0.0im -0.707107+0.0im
QXZoo.GateMap.s
— Methods()::SArray{Tuple{2,2},Complex{Float64},2,4}
Function which generates the S gate (sqrt(Z)).
Examples
julia> QXZoo.GateMap.s()
2×2 StaticArrays.SArray{Tuple{2,2},Complex{Float64},2,4} with indices SOneTo(2)×SOneTo(2):
1.0+0.0im 0.0+0.0im
0.0+0.0im 0.0+1.0im
QXZoo.GateMap.t
— Methodt()::SArray{Tuple{2,2},Complex{Float64},2,4}
Function which generates the T gate (sqrt(S)).
Examples
julia> QXZoo.GateMap.t()
2×2 StaticArrays.SArray{Tuple{2,2},Complex{Float64},2,4} with indices SOneTo(2)×SOneTo(2):
1.0+0.0im 0.0+0.0im
0.0+0.0im 0.707107+0.707107im
QXZoo.GateMap.I
— MethodI()::SArray{Tuple{2,2},Complex{Float64},2,4}
Function which generates the 2x2 identity gate.
Examples
julia> QXZoo.GateMap.I()
2×2 StaticArrays.SArray{Tuple{2,2},Complex{Float64},2,4} with indices SOneTo(2)×SOneTo(2):
1.0+0.0im 0.0+0.0im
0.0+0.0im 1.0+0.0im
QXZoo.GateMap.r_x
— Methodr_x(θ::Number)::SArray{Tuple{2,2},Complex{Float64},2,4}
Function which generates the parametric r_x gate: exp(-0.5imθx())
Examples
julia> QXZoo.GateMap.r_x(pi/3)
2×2 StaticArrays.SArray{Tuple{2,2},Complex{Float64},2,4} with indices SOneTo(2)×SOneTo(2):
0.866025+0.0im 0.0-0.5im
0.0-0.5im 0.866025+0.0im
QXZoo.GateMap.r_y
— Methodr_y(θ::Number)::SArray{Tuple{2,2},Complex{Float64},2,4}
Function which generates the parametric r_y gate: exp(-0.5imθy())
Examples
julia> QXZoo.GateMap.r_y(pi/6)
2×2 StaticArrays.SArray{Tuple{2,2},Complex{Float64},2,4} with indices SOneTo(2)×SOneTo(2):
0.965926+0.0im -0.258819+0.0im
0.258819+0.0im 0.965926+0.0im
QXZoo.GateMap.r_z
— Methodr_z(θ::Number)::SArray{Tuple{2,2},Complex{Float64},2,4}
Function which generates the parametric r_z gate: exp(-0.5imθz())
Examples
julia> QXZoo.GateMap.r_z(pi/2)
2×2 StaticArrays.SArray{Tuple{2,2},Complex{Float64},2,4} with indices SOneTo(2)×SOneTo(2):
0.707107-0.707107im 0.0+0.0im
0.0+0.0im 0.707107+0.707107im
QXZoo.GateMap.r_phase
— Methodr_phase(θ::Number)::SArray{Tuple{2,2},Complex{Float64},2,4}
Function which generates the parametric phase shifting gate [1 0; 0 exp(1im*θ)]. Note, this is not the Phase gate.
Examples
julia> QXZoo.GateMap.r_phase(pi/4)
2×2 StaticArrays.SArray{Tuple{2,2},Complex{Float64},2,4} with indices SOneTo(2)×SOneTo(2):
1.0+0.0im 0.0+0.0im
0.0+0.0im 0.707107+0.707107im
QXZoo.GateMap.c_x
— Methodc_x()::SArray{Tuple{4,4},Complex{Float64},2,16}
Function which generates the controlled Pauli-X gate as a block diagonal 4x4 matrix.
Examples
julia> QXZoo.GateMap.c_x()
4×4 StaticArrays.SArray{Tuple{4,4},Complex{Float64},2,16} with indices SOneTo(4)×SOneTo(4):
1.0+0.0im 0.0+0.0im 0.0+0.0im 0.0+0.0im
0.0+0.0im 1.0+0.0im 0.0+0.0im 0.0+0.0im
0.0+0.0im 0.0+0.0im 0.0+0.0im 1.0+0.0im
0.0+0.0im 0.0+0.0im 1.0+0.0im 0.0+0.0im
QXZoo.GateMap.c_y
— Methodc_y()::SArray{Tuple{4,4},Complex{Float64},2,16}
Function which generates the controlled Pauli-X gate as a block diagonal 4x4 matrix.
Examples
julia> QXZoo.GateMap.c_y()
4×4 StaticArrays.SArray{Tuple{4,4},Complex{Float64},2,16} with indices SOneTo(4)×SOneTo(4):
1.0+0.0im 0.0+0.0im 0.0+0.0im 0.0+0.0im
0.0+0.0im 1.0+0.0im 0.0+0.0im 0.0+0.0im
0.0+0.0im 0.0+0.0im 0.0+0.0im 0.0-1.0im
0.0+0.0im 0.0+0.0im 0.0+1.0im 0.0+0.0im
QXZoo.GateMap.c_z
— Methodc_z()::SArray{Tuple{4,4},Complex{Float64},2,16}
Function which generates the controlled Pauli-X gate as a block diagonal 4x4 matrix.
Examples
julia> QXZoo.GateMap.c_z()
4×4 StaticArrays.SArray{Tuple{4,4},Complex{Float64},2,16} with indices SOneTo(4)×SOneTo(4):
1.0+0.0im 0.0+0.0im 0.0+0.0im 0.0+0.0im
0.0+0.0im 1.0+0.0im 0.0+0.0im 0.0+0.0im
0.0+0.0im 0.0+0.0im 1.0+0.0im 0.0+0.0im
0.0+0.0im 0.0+0.0im 0.0+0.0im -1.0+0.0im
QXZoo.GateMap.c_r_x
— Methodc_r_x(θ::Number)::SArray{Tuple{4,4},Complex{Float64},2,16}
Function which generates the controlled parametric r_x gate as a block diagonal 4x4 matrix.
Examples
julia> QXZoo.GateMap.c_r_x(pi/3)
4×4 StaticArrays.SArray{Tuple{4,4},Complex{Float64},2,16} with indices SOneTo(4)×SOneTo(4):
1.0+0.0im 0.0+0.0im 0.0+0.0im 0.0+0.0im
0.0+0.0im 1.0+0.0im 0.0+0.0im 0.0+0.0im
0.0+0.0im 0.0+0.0im 0.866025+0.0im 0.0-0.5im
0.0+0.0im 0.0+0.0im 0.0-0.5im 0.866025+0.0im
QXZoo.GateMap.c_r_y
— Methodc_r_y(θ::Number)::SArray{Tuple{4,4},Complex{Float64},2,16}
Function which generates the controlled parametric r_y gate as a block diagonal 4x4 matrix.
Examples
julia> QXZoo.GateMap.c_r_y(pi/4)
4×4 StaticArrays.SArray{Tuple{4,4},Complex{Float64},2,16} with indices SOneTo(4)×SOneTo(4):
1.0+0.0im 0.0+0.0im 0.0+0.0im 0.0+0.0im
0.0+0.0im 1.0+0.0im 0.0+0.0im 0.0+0.0im
0.0+0.0im 0.0+0.0im 0.92388+0.0im -0.382683+0.0im
0.0+0.0im 0.0+0.0im 0.382683+0.0im 0.92388+0.0im
QXZoo.GateMap.c_r_z
— Methodc_r_z(θ::Number)::SArray{Tuple{4,4},Complex{Float64},2,16}
Function which generates the controlled parametric r_y gate as a block diagonal 4x4 matrix.
Examples
julia> QXZoo.GateMap.c_r_z(pi/6)
4×4 StaticArrays.SArray{Tuple{4,4},Complex{Float64},2,16} with indices SOneTo(4)×SOneTo(4):
1.0+0.0im 0.0+0.0im 0.0+0.0im 0.0+0.0im
0.0+0.0im 1.0+0.0im 0.0+0.0im 0.0+0.0im
0.0+0.0im 0.0+0.0im 0.965926-0.258819im 0.0+0.0im
0.0+0.0im 0.0+0.0im 0.0+0.0im 0.965926+0.258819im
QXZoo.GateMap.c_r_phase
— Methodc_r_phase(θ::Number)::SArray{Tuple{4,4},Complex{Float64},2,16}
Function which generates the controlled parametric phase shifting gate [1 0; 0 exp(1im*θ)] as a block diagonal 4x4 matrix.
Note, this is not the controlled Phase gate.
Examples
julia> QXZoo.GateMap.c_r_phase(pi/9)
4×4 StaticArrays.SArray{Tuple{4,4},Complex{Float64},2,16} with indices SOneTo(4)×SOneTo(4):
1.0+0.0im 0.0+0.0im 0.0+0.0im 0.0+0.0im
0.0+0.0im 1.0+0.0im 0.0+0.0im 0.0+0.0im
0.0+0.0im 0.0+0.0im 1.0+0.0im 0.0+0.0im
0.0+0.0im 0.0+0.0im 0.0+0.0im 0.939693+0.34202im