Circuits

The Circuit struct is used to represent a gate-based quantum computation on qubits. Circuits 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.CircuitType
Circuit

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.CircuitMethod
Circuit(m::Moments, ixs::Vector, rts::Vector{Result}, bri::Vector)

Construct a Circuit from a set of Moments, a vector of Instructions, a vector of Results, and a vector of basis rotation instructions.

Braket.CircuitMethod
Circuit(v)

Construct a Circuit from a Vector-like v containing tuples of:

  • a Gate, Noise, or Result
  • 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.QubitType
Qubit <: Integer

Wrapper struct representing a qubit.

Examples

julia> q = Qubit(0)
Qubit(0)

julia> q == 0
true
Braket.QubitSetType
QubitSet

An OrderedSet-like object which represents the qubits a Circuit, Instruction, or Result acts on and their ordering. Elements may be Ints or Qubits.

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.FreeParameterType
FreeParameter
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.depthFunction
depth(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.qubitsFunction
qubits(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_countFunction
qubit_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.InstructionType
Instruction
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.irFunction
ir(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 Circuits. 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.IRTypeConstant
IRType

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 :OpenQASM, 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[]
:OpenQASM

julia> IRType[] = :JAQCD;

julia> IRType[]
:JAQCD

julia> IRType[] = :OpenQASM;
Braket.OpenQASMSerializationPropertiesType
OpenQASMSerializationProperties(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.