Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ jobs:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'push' || !github.event.pull_request.draft }}
needs: [os-test, version-test]
continue-on-error: true
strategy:
fail-fast: true
matrix:
Expand Down
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Braket"
uuid = "19504a0f-b47d-4348-9127-acc6cc69ef67"
authors = ["Katharine Hyatt <hyatkath@amazon.com>"]
version = "0.9.6"
authors = ["Katharine Hyatt <hyatkath@amazon.com>", "Amazon Web Services"]
version = "0.10.0"

[deps]
AWS = "fbe9abb3-538b-5e4e-ba9e-bc94f4f92ebc"
Expand Down
4 changes: 3 additions & 1 deletion PyBraket/CondaPkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
python = ">=3.11,<3.14"
pydantic = ""
scipy = ""
numpy = ""
numpy = "<2.5"
numba = ""
llvmlite = ""

[pip.deps]
amazon-braket-sdk = ">=1.81.0"
Expand Down
6 changes: 3 additions & 3 deletions PyBraket/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "PyBraket"
uuid = "e85266a6-1825-490b-a80e-9b9469c53660"
authors = ["Katharine Hyatt <hyatkath@amazon.com>"]
version = "0.9.6"
authors = ["Katharine Hyatt <hyatkath@amazon.com>", "Amazon Web Services"]
version = "0.10.0"

[deps]
Braket = "19504a0f-b47d-4348-9127-acc6cc69ef67"
Expand All @@ -14,7 +14,7 @@ StructTypes = "856f2bd8-1eba-4b0a-8007-ebc267875bd4"

[compat]
Aqua = "0.8"
Braket = "0.9"
Braket = "0.10"
CondaPkg = "0.2"
DataStructures = "0.18"
LinearAlgebra = "1"
Expand Down
4 changes: 3 additions & 1 deletion PyBraket/test/CondaPkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
python = ">=3.11,<3.14"
pydantic = ""
scipy = ""
numpy = ""
numpy = "<2.5"
numba = ""
llvmlite = ""

[pip.deps]
amazon-braket-sdk = ">=1.81.0"
17 changes: 3 additions & 14 deletions src/Braket.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,15 @@ include("utils.jl")
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
Currently, only `:OpenQASM` (the OpenQASM3 representation) is supported.

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[]`.
By default, `IRType` is initialized to `:OpenQASM`. The current default value
can be checked by calling `IRType[]`.

# Examples
```jldoctest
julia> IRType[]
:OpenQASM

julia> IRType[] = :JAQCD;

julia> IRType[]
:JAQCD

julia> IRType[] = :OpenQASM;
```
"""
const IRType = Ref{Symbol}()
Expand Down Expand Up @@ -114,7 +104,6 @@ include("raw_jobs_config.jl")
include("raw_task_result_types.jl")
include("operators.jl")
include("irtypes.jl")
ir(x, ::Val{:JAQCD}; kwargs...) = StructTypes.lower(x)
ir(x) = ir(x, Val(IRType[]))
include("observables.jl")
using .Observables
Expand Down
17 changes: 1 addition & 16 deletions src/circuit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,6 @@ QubitSet with 2 elements:
```
"""
qubits(c::Circuit) = (qs = union!(copy(c.moments._qubits), c.qubit_observable_set); QubitSet(qs))
function qubits(p::Program)
inst_qubits = mapreduce(ix->ix.target, union, p.instructions, init=Set{Int}())
bri_qubits = mapreduce(ix->ix.target, union, p.basis_rotation_instructions, init=Set{Int}())
res_qubits = mapreduce(ix->(hasproperty(ix, :targets) && !isnothing(ix.targets)) ? reduce(vcat, ix.targets) : Set{Int}(), union, p.results, init=Set{Int}())
return union(inst_qubits, bri_qubits, res_qubits)
end
"""
qubit_count(c::Circuit) -> Int

Expand All @@ -293,15 +287,9 @@ julia> qubit_count(c)
```
"""
qubit_count(c::Circuit) = length(qubits(c))
qubit_count(p::Program) = length(qubits(p))

(rt::Result)(c::Circuit) = add_result_type!(c, rt)

Base.convert(::Type{Circuit}, p::Program) = Circuit(Moments(p.instructions), p.instructions, Result[StructTypes.constructfrom(Result, r) for r in p.results], p.basis_rotation_instructions)
Base.convert(::Type{Program}, c::Circuit) = (basis_rotation_instructions!(c); return Program(braketSchemaHeader("braket.ir.jaqcd.program" ,"1"), c.instructions, ir.(c.result_types, Val(:JAQCD)), c.basis_rotation_instructions))
Circuit(p::Program) = convert(Circuit, p)
Program(c::Circuit) = convert(Program, c)

function _add_measure!(c::Circuit, target_qubits::QubitSet)
for (idx, target) in enumerate(target_qubits)
num_qubits_measured = !isempty(c.measure_targets) && length(target_qubits) == 1 ? length(c.measure_targets) : 0
Expand Down Expand Up @@ -440,7 +428,7 @@ end
Convert a [`Circuit`](@ref) 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`](@ref),
which can be modified. Currently `:JAQCD` and `:OpenQASM` are supported for `Circuit`s.
which can be modified. Currently only `:OpenQASM` is supported for `Circuit`s.
If writing to `OpenQASM` IR, optional [`OpenQASMSerializationProperties`](@ref) may be specified.
"""
ir(c::Circuit; serialization_properties::SerializationProperties=OpenQASMSerializationProperties()) = ir(c, Val(IRType[]), serialization_properties=serialization_properties)
Expand All @@ -454,9 +442,6 @@ function ir(c::Circuit, ::Val{:OpenQASM}; serialization_properties::Serializatio
end
return OpenQasmProgram(header_dict[OpenQasmProgram], join(vcat(header, ixs, rts), "\n"), nothing)
end
ir(c::Circuit, ::Val{:JAQCD}; kwargs...) = convert(Program, c)
ir(p::Program, ::Val{:JAQCD}; kwargs...) = p
ir(p::Program; kwargs...) = ir(p, Val(:JAQCD); kwargs...)

# convenience ctor for OpenQasmProgram
OpenQasmProgram(source::String; inputs::Union{Nothing, Dict}=nothing) = OpenQasmProgram(header_dict[OpenQasmProgram], source, inputs)
Expand Down
2 changes: 0 additions & 2 deletions src/compiler_directive.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ will not be modified by any further compilation steps.
struct EndVerbatimBox <: CompilerDirective end
counterpart(s::StartVerbatimBox) = EndVerbatimBox()
counterpart(e::EndVerbatimBox) = StartVerbatimBox()
ir(s::StartVerbatimBox, ::Val{:JAQCD}; kwargs...) = IR.StartVerbatimBox("StartVerbatimBox", "start_verbatim_box")
ir(s::EndVerbatimBox, ::Val{:JAQCD}; kwargs...) = IR.EndVerbatimBox("EndVerbatimBox", "end_verbatim_box")
ir(s::StartVerbatimBox, ::Val{:OpenQASM}; kwargs...) = "#pragma braket verbatim\nbox{"
ir(s::EndVerbatimBox, ::Val{:OpenQASM}; kwargs...) = "}"
ir(c::CompilerDirective; kwargs...) = ir(c, Val(IRType[]); kwargs...)
Expand Down
13 changes: 0 additions & 13 deletions src/gates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,6 @@ targets_and_controls(::Val{1}, ::Val{1}, target::QubitSet) = (target[1
targets_and_controls(::Val{1}, ::Val{N}, target::QubitSet) where {N} = (target[1], target[2:end])
targets_and_controls(::Val{NC}, ::Val{1}, target::QubitSet) where {NC} = (target[1:NC], target[NC+1])
targets_and_controls(::Val{NC}, ::Val{NT}, target::QubitSet) where {NC, NT} = (target[1:NC], target[NC+1:NC+NT])
function ir(g::G, target::QubitSet, ::Val{:JAQCD}; kwargs...) where {G<:Gate}
t_c = targets_and_controls(g, target)
if isempty(t_c[1])
return ir_typ(g)(angles(g)..., t_c[2], label(g))
else
return ir_typ(g)(angles(g)..., t_c[1], t_c[2], label(g))
end
end
function ir(g::G, target::QubitSet, ::Val{:OpenQASM}; serialization_properties=OpenQASMSerializationProperties()) where {G<:Gate}
t = format_qubits(target, serialization_properties)
ir_string = ir_str(g) * " " * t
Expand Down Expand Up @@ -161,10 +153,6 @@ n_targets(g::Unitary) = qubit_count(g)
n_controls(g::Unitary) = 0

ir_str(g::Unitary) = "#pragma braket unitary(" * format_matrix(g.matrix) * ")"
function ir(g::Unitary, target::QubitSet, ::Val{:JAQCD}; kwargs...)
mat = complex_matrix_to_ir(g.matrix)
return IR.Unitary(collect(target), mat, "unitary")
end

"""
GPhase <: Gate
Expand All @@ -183,7 +171,6 @@ ir_typ(::Type{GPhase}) = IR.UndefinedGate
label(::Type{GPhase}) = "gphase"
n_targets(g::GPhase) = 0
n_controls(g::GPhase) = 0
ir(g::GPhase, target::QubitSet, ::Val{:JAQCD}; kwargs...) = throw(MethodError(ir, (g, target, Val(:JAQCD))))
targets_and_controls(g::GPhase, target::QubitSet) = ((), tuple(target...))
StructTypes.StructType(::Type{<:Gate}) = StructTypes.Struct()

Expand Down
15 changes: 0 additions & 15 deletions src/local_simulator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,6 @@ function _run_internal(simulator, circuit::Circuit, args...; shots::Int=0, input
full_program = OpenQasmProgram(program.braketSchemaHeader, program.source, full_inputs)
r = simulate(simulator, full_program, shots; kwargs...)
return format_result(r)
elseif haskey(properties(simulator).action, "braket.ir.jaqcd.program")
validate_circuit_and_shots(circuit, shots)
program = ir(circuit, Val(:JAQCD))
qubits = qubit_count(circuit)
r = simulate(simulator, program, qubits, shots; inputs=inputs, kwargs...)
return format_result(r)
else
throw(ErrorException("$(typeof(simulator)) does not support qubit gate-based programs."))
end
Expand All @@ -167,12 +161,3 @@ function _run_internal(simulator, program::OpenQasmProgram, args...; shots::Int=
throw(ErrorException("$(typeof(simulator)) does not support qubit gate-based programs."))
end
end
function _run_internal(simulator, program::Program, args...; shots::Int=0, inputs::Dict{String, Float64}=Dict{String, Float64}(), kwargs...)
if haskey(properties(simulator).action, "braket.ir.jaqcd.program")
qubits = qubit_count(program)
r = simulate(simulator, program, qubits, shots; inputs=inputs, kwargs...)
return format_result(r)
else
throw(ErrorException("$(typeof(simulator)) does not support qubit gate-based programs."))
end
end
7 changes: 0 additions & 7 deletions src/noises.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ struct Kraus <: Noise
end
Kraus(mats::Vector{Vector{Vector{Vector{Float64}}}}) = Kraus(complex_matrix_from_ir.(mats))
Base.:(==)(k1::Kraus, k2::Kraus) = k1.matrices == k2.matrices
ir(g::Kraus, target::QubitSet, ::Val{:JAQCD}; kwargs...) = IR.Kraus(collect(target), [complex_matrix_to_ir(mat) for mat in g.matrices], "kraus")
function ir(g::Kraus, target::QubitSet, ::Val{:OpenQASM}; serialization_properties::SerializationProperties=OpenQASMSerializationProperties())
t = format_qubits(collect(target), serialization_properties)
ms = join(format_matrix.(g.matrices), ", ")
Expand Down Expand Up @@ -194,7 +193,6 @@ Pauli channel noise operation on two qubits.
TwoQubitPauliChannel = MultiQubitPauliChannel{2}
qubit_count(g::MultiQubitPauliChannel{N}) where {N} = N
Parametrizable(g::MultiQubitPauliChannel) = Parametrized()
ir(g::MultiQubitPauliChannel{N}, target::QubitSet, ::Val{:JAQCD}; kwargs...) where {N} = IR.MultiQubitPauliChannel(g.probabilities, collect(target), "multi_qubit_pauli_channel")
function MultiQubitPauliChannel(probabilities::Dict{String, <:Union{Float64, FreeParameter}})
N = length(first(keys(probabilities)))
return MultiQubitPauliChannel{N}(probabilities)
Expand All @@ -205,11 +203,6 @@ n_controls(n::Noise) = Val(0)
targets_and_controls(n::N, target::QubitSet) where {N<:Noise} = targets_and_controls(n_controls(n), n_targets(n), target)
for (N, IRN, label) in zip((:BitFlip, :PhaseFlip, :PauliChannel, :AmplitudeDamping, :PhaseDamping, :Depolarizing, :TwoQubitDephasing, :TwoQubitDepolarizing, :GeneralizedAmplitudeDamping), (:(IR.BitFlip), :(IR.PhaseFlip), :(IR.PauliChannel), :(IR.AmplitudeDamping), :(IR.PhaseDamping), :(IR.Depolarizing), :(IR.TwoQubitDephasing), :(IR.TwoQubitDepolarizing), :(IR.GeneralizedAmplitudeDamping)), ("bit_flip", "phase_flip", "pauli_channel", "amplitude_damping", "phase_damping", "depolarizing", "two_qubit_dephasing", "two_qubit_depolarizing", "generalized_amplitude_damping"))
@eval begin
function ir(n::$N, target::QubitSet, ::Val{:JAQCD}; kwargs...)
t_c = targets_and_controls(n, target)
ir_args = (getproperty(n, fn) for fn in fieldnames($N))
return $IRN(ir_args..., t_c[2], $label)
end
function ir(n::$N, target::QubitSet, ::Val{:OpenQASM}; serialization_properties=OpenQASMSerializationProperties())
t = format_qubits(target, serialization_properties)
ir_args = join([repr(getproperty(n, fn)) for fn in fieldnames($N)], ", ")
Expand Down
2 changes: 0 additions & 2 deletions src/observables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,6 @@ function Base.show(io::IO, s::Sum)
return
end
StructTypes.lower(s::Sum) = [StructTypes.lower(summand) for summand in s.summands]
ir(s::Sum, target::Vector{QubitSet}, ::Val{:JAQCD}; kwargs...) = throw(ErrorException("Sum observables are not supported in JAQCD."))
ir(s::Sum, target::Vector{<:IntOrQubit}, ::Val{:JAQCD}; kwargs...) = throw(ErrorException("Sum observables are not supported in JAQCD."))
function ir(s::Sum, target::Vector{QubitSet}, ::Val{:OpenQASM}; kwargs...)
length(s.summands) == length(target) || throw(DimensionMismatch("number of summands ($(length(s.summands))) must match length of targets vector ($(length(targets)))."))
for (ii, (term, term_target)) in enumerate(zip(s.summands, target))
Expand Down
2 changes: 0 additions & 2 deletions src/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ chars(::Type{Measure}) = ("M",)
chars(::Measure) = chars(Measure)
qubit_count(::Type{Measure}) = 1
qubit_count(::Measure) = qubit_count(Measure)
ir(m::Measure, target::QubitSet, ::Val{:JAQCD}; kwargs...) = error("measure instructions are not supported with JAQCD.")
function ir(m::Measure, target::QubitSet, ::Val{:OpenQASM}; serialization_properties=OpenQASMSerializationProperties())
instructions = Vector{String}(undef, length(target))
for (idx, qubit) in enumerate(target)
Expand Down Expand Up @@ -127,7 +126,6 @@ label(d::Microsecond) = "$(d.value)ms"
label(d::Nanosecond) = "$(d.value)ns"
label(d::Second) = "$(d.value)s"

ir(ix::Union{Reset, Barrier, Delay}, target::QubitSet, ::Val{:JAQCD}; kwargs...) = error("$(label(ix)) instructions are not supported with JAQCD.")
function ir(ix::Union{Reset, Barrier, Delay}, target::QubitSet, v::Val{:OpenQASM}; serialization_properties=OpenQASMSerializationProperties())
return join(("$(label(ix)) $(format_qubits(qubit, serialization_properties));" for qubit in target), "\n")
end
Loading
Loading