Circuits
The Circuit
struct is used to represent a gate-based quantum computation on qubits. Circuit
s can be built up iteratively by applying them as functors to operations like so:
julia> c = Circuit();
julia> c(H, Qubit(0));
julia> α = FreeParameter(:alpha);
julia> c(Rx, Qubit(1), α);
julia> c(Probability); # measures probability on all qubits
This functor syntax can also be used to set the value of free parameters:
julia> α = FreeParameter(:alpha);
julia> θ = FreeParameter(:theta);
julia> circ = Circuit([(H, 0), (Rx, 1, α), (Ry, 0, θ), (Probability,)]);
julia> new_circ = circ(theta=2.0, alpha=1.0);
julia> new_circ2 = circ(0.5); # sets the value of all FreeParameters to 0.5
Braket.Circuit
— TypeCircuit
A representation of a quantum circuit that contains the instructions to be performed on a quantum device and the requested result types.
See:
- Gates for all of the supported gates.
- Noises for all of the supported noise operations.
- Compiler Directives for all of the supported compiler directives.
- Results for all of the supported result types.
Braket.Circuit
— MethodCircuit()
Construct an empty Circuit
.
Braket.Circuit
— MethodCircuit(m::Moments, ixs::Vector, rts::Vector{Result}, bri::Vector)
Construct a Circuit
from a set of Moments
, a vector of Instruction
s, a vector of Result
s, and a vector of basis rotation instructions.
Braket.Circuit
— MethodCircuit(v)
Construct a Circuit
from a Vector
-like v
containing tuples of:
- a
Gate
,Noise
, orResult
- the target qubits on which to apply the operator
- any construction arguments to the operator, e.g. an angle or
Observable
Examples
julia> v = [(H, collect(0:10)), (Rx, 1, 0.2), (BitFlip, 0, 0.1)];
julia> Circuit(v);
Braket.Qubit
— TypeQubit <: Integer
Wrapper struct
representing a qubit.
Examples
julia> q = Qubit(0)
Qubit(0)
julia> q == 0
true
Braket.QubitSet
— TypeQubitSet
An OrderedSet
-like object which represents the qubits a Circuit
, Instruction
, or Result
acts on and their ordering. Elements may be Int
s or Qubit
s.
Examples
julia> QubitSet(1, Qubit(0))
QubitSet(1, Qubit(0))
julia> QubitSet([2, 1])
QubitSet(2, 1)
julia> QubitSet()
QubitSet()
julia> QubitSet(QubitSet(5, 1))
QubitSet(5, 1)
Braket.Operator
— TypeOperator
Abstract type representing operations that can be applied to a Circuit
. Subtypes include Gate
, Noise
, Observable
, and CompilerDirective
.
Braket.QuantumOperator
— TypeQuantumOperator < Operator
Abstract type representing quantum operations that can be applied to a Circuit
. Subtypes include Gate
and Noise
.
Braket.FreeParameter
— TypeFreeParameter
FreeParameter(name::Symbol) -> FreeParameter
Struct representing a free parameter, which may be used to initialize to a parametrized Gate
or Noise
and then given a fixed value later by supplying a mapping to a Circuit
.
Braket.depth
— Functiondepth(c::Circuit)
Returns the number of moments in c
. Also known as the "parallel gate depth".
Examples
julia> c = Circuit();
julia> H(c, 0);
julia> CNot(c, 0, 1);
julia> depth(c)
2
Braket.qubits
— Functionqubits(c::Circuit) -> QubitSet
Returns a QubitSet
containing all qubits that c
is defined on.
Examples
julia> c = Circuit();
julia> H(c, 0);
julia> CNot(c, 0, 1);
julia> qubits(c)
QubitSet(0, 1)
Braket.qubit_count
— Functionqubit_count(c::Circuit) -> Int
Returns the number of qubits that c
is defined on.
Examples
julia> c = Circuit();
julia> H(c, 0);
julia> CNot(c, 0, 1);
julia> qubit_count(c)
2
Output to IR
Braket.jl
provides several functions to transform a Circuit
into IR which will be transmitted to Amazon managed QPUs or simulators. Currently, two output formats supported are OpenQASM, and JAQCD (an Amazon Braket native IR). You can control how IR translation is done through the global variable IRType
and, if using OpenQASM, OpenQASMSerializationProperties
.
Braket.Instruction
— TypeInstruction
Instruction(o::Operator, target)
Represents a single operation applied to a Circuit
. Contains an operator
, which may be any subtype of Operator
, and a target
set of qubits to which the operator
is applied.
Examples
julia> Instruction(H(), 1)
Braket.Instruction(H(), QubitSet(1))
julia> Instruction(CNot(), [1, Qubit(4)])
Braket.Instruction(CNot(), QubitSet(1, Qubit(4)))
julia> Instruction(StartVerbatimBox(), QubitSet())
Braket.Instruction(StartVerbatimBox(), QubitSet())
Braket.ir
— Functionir(c::Circuit; serialization_properties::SerializationProperties=OpenQASMSerializationProperties())
Convert a Circuit
into IR that can be consumed by the Amazon Braket service, whether local simulators, on-demand simulators, or QPUs. The IR format to convert to by default is controlled by the global variable IRType
, which can be modified. Currently :JAQCD
and :OpenQASM
are supported for Circuit
s. If writing to OpenQASM
IR, optional OpenQASMSerializationProperties
may be specified.
ir(ahs::AnalogHamiltonianSimulation)
Generate IR from an AnalogHamiltonianSimulation
which can be run on a neutral atom simulator or quantum device.
Braket.IRType
— ConstantIRType
A Ref{Symbol}
which records which IR output format to use by default. Currently, two formats are supported:
:JAQCD
, the Amazon Braket IR:OpenQASM
, the OpenQASM3 representation
By default, IRType
is initialized to use :JAQCD
, although this may change in the future. The current default value can be checked by calling IRType[]
. To change the default IR format, set IRType[]
.
Examples
julia> IRType[]
:JAQCD
julia> IRType[] = :OpenQASM;
julia> IRType[]
:OpenQASM
julia> IRType[] = :JAQCD;
Braket.OpenQASMSerializationProperties
— TypeOpenQASMSerializationProperties(qubit_reference_type=VIRTUAL)
Contains information about how to serialize qubits when outputting to OpenQASM IR. The qubit_reference_type
argument may be one of VIRTUAL
or PHYSICAL
.