General functions

MimiqCircuitsBase.getoperation — Function
getoperation(operation)
getoperation(instruction)

Returns the quantum operation associated to the given instruction.

See also iswrapper.

Examples

julia> getoperation(Instruction(GateX(), 1))
X

julia> getoperation(GateSX())
X

julia> getoperation(GateCX())
X
source
MimiqCircuitsBase.numbits — Function
numbits(instruction)
numbits(circuit)

Number of classical bits on which the given operation or instruction is defined.

See also numqubits.

Examples

julia> numbits(GateCX())
0

julia> numbits(Measure())
1

julia> c = Circuit(); push!(c, Measure(), 1, 1); push!(c, Measure(),1,3)
1-qubit, 3-bit circuit with 2 instructions:
├── M @ q[1], c[1]
└── M @ q[1], c[3]

julia> numbits(c)
3
source
MimiqCircuitsBase.numqubits — Function
numqubits(operation)
numqubits(instruction)
numqubits(circuit)

Number of qubits on which the given operation or instruction is defined.

See also numbits.

Examples

julia> numqubits(GateCX())
2

julia> numqubits(Measure())
1

julia> c = Circuit(); push!(c, GateX(), 1); push!(c, GateCX(),3,6)
6-qubit circuit with 2 instructions:
├── X @ q[1]
└── CX @ q[3], q[6]

julia> numqubits(c)
6
source
MimiqCircuitsBase.opname — Function
opname(instruction)
opname(operation)

Name of the underlying quantum operation in a human readable format.

See also numqubits, numbits.

Examples

julia> opname(GateX())
"X"

julia> opname(GateRX(π/2))
"RX"

julia> opname(Instruction(GateCX(),1,2))
"CX"

julia> opname(QFT(4))
"QFT"
source
MimiqCircuitsBase.power — Function
power(operation, exponent)

Elevate an operation to a given exponent.

It performs simplifications when possible otherwise wraps the operation in a Power object. A floating point exponent that is exactly a fraction with denominator at most 1000 is treated as that fraction, so 0.5 behaves like 1//2.

See also Power, inverse, Inverse.

Examples

julia> power(GateX(), 1//2)
SX

julia> power(GateX(), 0.5)
SX

julia> GateX()^2
ID

julia> GateCSX()^2
CX
source
Symbolics.inverse — Function
inverse(circuit)
inverse(instruction)
inverse(operation)

Inverse of the given circuit, instruction or operation.

When the inverse is not a known operation, it will return an Inverse object that wraps the original operation.

Details

It throws an error if the object is not invertible. Such for example, in the case of non unitary operations, or circuits containing Measure or Reset.

See also matrix, isunitary, power.

Examples

julia> inverse(GateRX(λ))
RX(-λ)

julia> inverse(GateCSX())
C(SX†)
source
MimiqCircuitsBase.evaluate — Function
evaluate(object, dictionary)

Evaluate all the parametric expression in object using the values specified in the given in the variable, value dictionary, returning a new object constructed on the evaluated parameters.

A wrapper (Control, Inverse, Power, Parallel, Repeat, IfStatement, WhileStatement) or a Block without free symbols is returned unchanged. One with free symbols is rebuilt with control, inverse, power, parallel and repeat, which simplify where they can: Inverse(GateRX(θ)) evaluates to a GateRX, not to an Inverse.

Examples

Evaluate a single parametric gate

julia> @variables θ
1-element Vector{Symbolics.Num}:
 θ

julia> g  = GateRX(θ)
RX(θ)

julia> evaluate(g, Dict(θ => 3π))
RX(3π)

julia> evaluate(Inverse(GateRX(θ)), Dict(θ => 0.3))
RX(-0.3)
source
MimiqCircuitsBase.evaluate! — Method
evaluate!(circuit, d::Dict)

Replace the symbols of circuit with the values in d, in place, and return the circuit.

Symbols that are not in d stay symbolic. Use evaluate to get a new circuit instead.

Examples

julia> @variables θ φ;

julia> c = push!(Circuit(), GateRX(θ), 1);

julia> push!(c, GateRY(φ), 1);

julia> evaluate!(c, Dict(θ => 0.5))
1-qubit circuit with 2 instructions:
├── RX(0.5) @ q[1]
└── RY(φ) @ q[1]
source
MimiqCircuitsBase.issymbolic — Function
issymbolic(obj)

Checks whether the circuit contains any symbolic (unevaluated) parameters.

This method examines each instruction in the circuit to determine if any parameter remains symbolic (i.e., unevaluated). It recursively checks through each instruction and its nested operations, if any. Returns True if any parameter is symbolic (unevaluated), False if all parameters are fully evaluated.

Examples

julia> c = Circuit()
empty circuit

julia> push!(c, GateH(), 1)
1-qubit circuit with 1 instruction:
└── H @ q[1]

julia> issymbolic(c)
false

julia> @variables x y
2-element Vector{Symbolics.Num}:
 x
 y

julia> push!(c,Control(3,GateP(x+y)),1,2,3,4)
4-qubit circuit with 2 instructions:
├── H @ q[1]
└── C₃P(x + y) @ q[1:3], q[4]

julia> issymbolic(c)
true
source
MimiqCircuitsBase.listvars — Function
listvars(obj)

List the symbolic variables that appear in obj.

obj can be an operation, an Instruction, a Circuit, a ParameterTable or a SweepExperiment:

  • for an operation, the variables in its parameters. Wrappers such as Control, Inverse, Power, Parallel, Repeat, IfStatement and WhileStatement give the variables of the operation they wrap, and a Block those of all its instructions;
  • for an instruction, the variables of its operation;
  • for a circuit, the variables of all its instructions;
  • for a parameter table, the symbols it gives values to, in column order;
  • for a sweep experiment, the symbols of its table, which are those of its circuit.

Returns a Vector{Num} with each variable once, in the order they are first found. It is empty when obj has no symbolic parameters. Variables already substituted by evaluate are not listed.

Examples

julia> @variables θ φ
2-element Vector{Symbolics.Num}:
 θ
 φ

julia> listvars(GateRX(θ))
1-element Vector{Symbolics.Num}:
 θ

julia> c = Circuit();

julia> push!(c, GateRX(θ), 1);

julia> push!(c, Control(GateRY(φ)), 1, 2);

julia> push!(c, GateRX(2θ), 2);

julia> listvars(c)
2-element Vector{Symbolics.Num}:
 θ
 φ

julia> listvars(evaluate(c, Dict(θ => 0.1)))
1-element Vector{Symbolics.Num}:
 φ

julia> listvars(GateH())
Symbolics.Num[]

See also issymbolic, evaluate.

source
MimiqCircuitsBase.Measure — Type
Measure()

Single qubit measurement operation in the computational basis

The operation projects the quantum state and stores the result of such measurement in a classical register.

Warn

Measure is non-reversible.

See also Operation, Reset.

Examples

julia> Measure()
M

julia> c = push!(Circuit(), Measure, 1, 1)
1-qubit, 1-bit circuit with 1 instruction:
└── M @ q[1], c[1]

julia> push!(c, Measure(), 3, 4)
3-qubit, 4-bit circuit with 2 instructions:
├── M @ q[1], c[1]
└── M @ q[3], c[4]
source
MimiqCircuitsBase.MeasureX — Type
MeasureX()

Single qubit measurement operation in the X basis.

The operation projects the quantum state and stores the result of such measurement in a classical register.

This operation is equivalent to the sequence GateH, Measure, GateH.

Warn

Measure is non-reversible.

See also Measure, Operation, Reset.

Examples

julia> Measure()
M

julia> decompose(MeasureX())
1-qubit, 1-bit circuit with 3 instructions:
├── U(π/2,0,π) @ q[1]
├── M @ q[1], c[1]
└── U(π/2,0,π) @ q[1]

julia> c = push!(Circuit(), Measure, 1, 1)
1-qubit, 1-bit circuit with 1 instruction:
└── M @ q[1], c[1]

julia> push!(c, Measure(), 3, 4)
3-qubit, 4-bit circuit with 2 instructions:
├── M @ q[1], c[1]
└── M @ q[3], c[4]
source
MimiqCircuitsBase.MeasureY — Type
MeasureY()

Single qubit measurement operation in the Y basis.

The operation projects the quantum state and stores the result of such measurement in a classical register.

This operation is equivalent to the sequence GateSDG, GateH, Measure, GateH, GateS.

Warn

Measure is non-reversible.

See also Measure, Operation, Reset.

Examples

julia> MeasureY()
MeasureY

julia> decompose(MeasureY())
1-qubit, 1-bit circuit with 11 instructions:
├── U(π/2,0,π) @ q[1]
├── U(0,0,π/2) @ q[1]
├── U(π/2,0,π) @ q[1]
├── U(0,0,π) @ q[1]
├── U(0,0,0,-1π/4) @ q[1]
├── M @ q[1], c[1]
├── U(π/2,0,π) @ q[1]
├── U(0,0,π/2) @ q[1]
├── U(π/2,0,π) @ q[1]
├── U(0,0,π) @ q[1]
└── U(0,0,0,-1π/4) @ q[1]

julia> c = push!(Circuit(), MeasureY, 1, 1)
1-qubit, 1-bit circuit with 1 instruction:
└── MeasureY @ q[1], c[1]

julia> push!(c, MeasureY(), 3, 4)
3-qubit, 4-bit circuit with 2 instructions:
├── MeasureY @ q[1], c[1]
└── MeasureY @ q[3], c[4]
source

Serialization

MimiqCircuitsBase.WIRE_FORMAT_VERSION — Constant
WIRE_FORMAT_VERSION

Version of the MIMIQ wire format (protobuf schemas + JSON request/response envelope) spoken by this build. Versioned independently of the package release so API-only changes do not force client/executor incompatibility. A client and an executor must speak the same version. See WIRE_FORMAT.md for the surface and bump rules.

source
MimiqCircuitsBase.loadproto — Function
loadproto(fname, Circuit)
loadproto(fname, QCSResults)

Deserialize a Circuit, a QCSResults, or a Hamiltonian object from a ProtoBuf file.

source
MimiqCircuitsBase.saveproto — Function
saveproto(fname, c::Circuit)
saveproto(fname, c::QCSResults)
saveproto(fname, h::Hamiltonian)

Serialize a Circuit, a QCSResults, or a Hamiltonian, object to a ProtoBuf file.

source