Skip to content

Commit

Permalink
fix: bump package versions, test on 1.9, and fix warnings (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
kshyatt-aws authored Feb 3, 2023
1 parent b5dab03 commit cfb67a9
Show file tree
Hide file tree
Showing 15 changed files with 106 additions and 82 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@ jobs:
runs-on: ubuntu-latest
# don't run on draft PRs
if: ${{ github.event_name == 'push' || !github.event.pull_request.draft }}
# allow failures on nightly Julia
continue-on-error: ${{ matrix.version == 'nightly' }}
# allow failures on nightly or beta Julia
continue-on-error: ${{ matrix.version == 'nightly' || matrix.version == '1.9.0-beta3'}}
strategy:
fail-fast: true
max-parallel: 2
matrix:
group:
- Braket-unit
- PyBraket-unit
version: ['1.6', '1.7', '1.8', 'nightly']
version: ['1.6', '1.7', '1.8', '1.9.0-beta3', 'nightly']
arch: ['x64']
steps:
- uses: actions/checkout@v1
Expand Down
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ AWSS3 = "=0.10.2"
Aqua = "=0.6"
AxisArrays = "=0.4.6"
CSV = "=0.10.9"
Compat = "=4.5.0"
Compat = "=4.6.0"
DataStructures = "=0.18.13"
DecFP = "=1.3.1"
Distributions = "=0.25.76"
Graphs = "=1.7.4"
HTTP = "=1.7.3"
HTTP = "=1.7.4"
JSON3 = "=1.12.0"
Mocking = "=0.7.5"
NamedTupleTools = "=0.14.3"
Expand Down
2 changes: 1 addition & 1 deletion PyBraket/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ StructTypes = "856f2bd8-1eba-4b0a-8007-ebc267875bd4"
[compat]
Aqua = "=0.6"
Braket = "=0.3.0"
CondaPkg = "=0.2.15"
CondaPkg = "=0.2.17"
DataStructures = "=0.18.13"
PythonCall = "=0.9.10"
StructTypes = "=1.10.0"
Expand Down
1 change: 0 additions & 1 deletion PyBraket/test/circuits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ using PythonCall: pyconvert, Py, pyisTrue, pyisinstance
py_obs = Py(2.0*tp + ho)
@test pyisinstance(py_obs, PyBraket.braketobs.Sum)
@test pyisinstance(py_obs.summands[0], PyBraket.braketobs.TensorProduct)
@show py_obs.summands[0].coefficient
@test pyconvert(Float64, py_obs.summands[0].coefficient) == 2.0
@test pyisinstance(py_obs.summands[1], PyBraket.braketobs.Hermitian)
end
Expand Down
6 changes: 4 additions & 2 deletions PyBraket/test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using Test, Aqua, Braket, Braket.AWS, PyBraket

Aqua.test_all(PyBraket, ambiguities=false, unbound_args=false, piracy=false)
Aqua.test_ambiguities(PyBraket)
withenv("JULIA_CONDAPKG_VERBOSITY"=>"-1") do
Aqua.test_all(PyBraket, ambiguities=false, unbound_args=false, piracy=false)
Aqua.test_ambiguities(PyBraket)
end

function set_aws_creds(test_type)
if test_type == "unit"
Expand Down
11 changes: 6 additions & 5 deletions src/Braket.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export Circuit, QubitSet, Qubit, Device, AwsDevice, AwsQuantumTask, AwsQuantumTa
export metadata, status, Observable, Result, FreeParameter, AwsQuantumJob, Tracker, simulator_tasks_cost, qpu_tasks_cost
export arn, cancel, state, result, results, name, download_result, id, ir, isavailable, search_devices, get_devices
export provider_name, properties, type
export apply_gate_noise!
export apply_gate_noise!, apply
export logs, log_metric, metrics
export depth, qubit_count, qubits, ir, IRType, OpenQASMSerializationProperties
export OpenQasmProgram
Expand All @@ -13,10 +13,11 @@ export AdjointGradient, Expectation, Sample, Variance, Amplitude, Probability, S

using AWSS3
using AWS
using AWS: @service, AWSConfig, global_aws_config
@service BRAKET use_response_type=false
@service IAM
@service CLOUDWATCH_LOGS
using AWS: @service, AWSConfig, global_aws_config, apply
import AWS.Mocking: apply
@service BRAKET use_response_type=true
@service IAM use_response_type=true
@service CLOUDWATCH_LOGS use_response_type=true

using Compat
using CSV
Expand Down
2 changes: 1 addition & 1 deletion src/device.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ whether the device is currently online.
"""
function refresh_metadata!(d::AwsDevice)
dev_name = d._arn
metadata = convert(Dict, BRAKET.get_device(HTTP.escapeuri(dev_name), aws_config=d._config))
metadata = parse(BRAKET.get_device(HTTP.escapeuri(dev_name), aws_config=d._config))
d._name = metadata["deviceName"]
d._status = metadata["deviceStatus"]
d._type = metadata["deviceType"]
Expand Down
2 changes: 1 addition & 1 deletion src/jobs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ use previously cached metadata, if available, otherwise fetch it from
the Braket service. If the second argument is `::Val{false}` (default),
do not use previously cached metadata, and fetch fresh metadata from the Braket service.
"""
metadata(j::AwsQuantumJob, ::Val{false}) = (payload = get_job(j); return convert(Dict, payload))
metadata(j::AwsQuantumJob, ::Val{false}) = parse(get_job(j))
metadata(j::AwsQuantumJob, ::Val{true}) = !isempty(j._metadata) ? j._metadata : metadata(j, Val(false))
metadata(j::AwsQuantumJob) = metadata(j, Val(false))

Expand Down
2 changes: 1 addition & 1 deletion src/noise_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,4 @@ function apply(nm::NoiseModel, c::Circuit)
n_c = apply_readout_noise!(n_c, ixs.readout_noise)
return n_c
end
(c::Circuit)(nm::NoiseModel) = apply(nm, c)
(c::Circuit)(nm::NoiseModel) = apply(nm, c)
8 changes: 4 additions & 4 deletions src/task.jl
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,10 @@ If the second argument is `::Val{false}`, do not use previously cached
metadata, and fetch fresh metadata from the Braket service.
"""
function metadata(t::AwsQuantumTask, ::Val{false})
payload = BRAKET.get_quantum_task(HTTP.escapeuri(t.arn))
resp = Dict(zip(keys(payload), values(payload)))
broadcast_event!(TaskStatusEvent(t.arn, resp["status"]))
return resp
resp = BRAKET.get_quantum_task(HTTP.escapeuri(t.arn))
payload = parse(resp)
broadcast_event!(TaskStatusEvent(t.arn, payload["status"]))
return payload
end
metadata(t::AwsQuantumTask, ::Val{true}) = !isempty(t._metadata) ? t._metadata : metadata(t, Val(false))

Expand Down
14 changes: 11 additions & 3 deletions test/integ_tests/cost_tracking.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
using Braket, Braket.AWS, Dates, Test
using AWS: @service, AWSConfig, global_aws_config
@service BRAKET use_response_type=false
@service BRAKET use_response_type=true

@testset "Cost tracking" begin
@testset "QPU tracking" begin
circuit = Circuit([(H, 0)])
t = Braket.Tracker()
n_available = 0
for arn = ("arn:aws:braket:eu-west-2::device/qpu/oqc/Lucy", "arn:aws:braket:us-west-1::device/qpu/rigetti/Aspen-M-2", "arn:aws:braket:::device/qpu/ionq/ionQdevice")
d = AwsDevice(arn)
Braket.isavailable(d) && d(circuit, shots=10)
if Braket.isavailable(d)
d(circuit, shots=10)
n_available += 1
end
end
if n_available > 0
@test qpu_tasks_cost(t) > 0.0
else
@test qpu_tasks_cost(t) == 0.0
end
@test qpu_tasks_cost(t) > 0
end
@testset "Simulator tracking" begin
circuit = Circuit([(H, 0), (CNot, 0, 1)])
Expand Down
4 changes: 2 additions & 2 deletions test/integ_tests/create_quantum_job.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using AWS, AWSS3, Braket, JSON3, Test

@service S3 use_response_type = true
@service S3 use_response_type=true

@testset "Quantum Job Creation" begin
region = aws_get_region()
Expand Down Expand Up @@ -148,4 +148,4 @@ using AWS, AWSS3, Braket, JSON3, Test
end
end
end
end
end
9 changes: 9 additions & 0 deletions test/integ_tests/simulator_quantum_task.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ end
end

@testset "Simulator Quantum Task" begin
@testset "Creating and cancelling a task" begin
@testset for simulator_arn in SIMULATOR_ARNS
device = AwsDevice(simulator_arn)
bell = bell_circ()
task = device(bell, shots=SHOTS, s3_destination_folder=s3_destination_folder)
cancel(task)
@test state(task) ["CANCELLING", "CANCELLED"]
end
end
@testset "No result types Bell pair" begin
@testset for simulator_arn in SIMULATOR_ARNS
device = AwsDevice(simulator_arn)
Expand Down
4 changes: 2 additions & 2 deletions test/noise_model.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Braket, Braket.Observables, Test, JSON3

using Braket: apply, NoiseModel, add_noise!, insert_noise!, remove_noise!, from_filter, GateCriteria, QubitInitializationCriteria, UnitaryGateCriteria, ObservableCriteria
using Braket: NoiseModel, add_noise!, insert_noise!, remove_noise!, from_filter, GateCriteria, QubitInitializationCriteria, UnitaryGateCriteria, ObservableCriteria
import Braket: I as I

h_unitary() = (1/√2).*[1.0 1.0; 1.0 -1.0]
Expand Down Expand Up @@ -316,4 +316,4 @@ end
@test result_circuit.instructions == expected_circuit.instructions
@test result_circuit == expected_circuit
end
end
end
113 changes: 59 additions & 54 deletions test/task_batch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,68 +90,73 @@ XANADU_ARN = "arn:aws:braket:us-east-1::device/qpu/xanadu/Borealis"
end
end
@testset "result" begin
mtd_dict = Dict("status"=>"COMPLETED", "outputS3Bucket"=>"fake_bucket", "outputS3Directory"=>"fake_dir")
function f(http_backend, request, response_stream)
if request.service == "s3"
return Braket.AWS.Response(Braket.HTTP.Response(200), IOBuffer(JSON3.write(mock_result(c))))
else
return Braket.AWS.Response(Braket.HTTP.Response(200, ["Content-Type"=>"application/json"]), IOBuffer(JSON3.write(mtd_dict)))
@testset "success" begin
mtd_dict = Dict("status"=>"COMPLETED", "outputS3Bucket"=>"fake_bucket", "outputS3Directory"=>"fake_dir")
function f(http_backend, request, response_stream)
if request.service == "s3"
return Braket.AWS.Response(Braket.HTTP.Response(200), IOBuffer(JSON3.write(mock_result(c))))
else
return Braket.AWS.Response(Braket.HTTP.Response(200, ["Content-Type"=>"application/json"]), IOBuffer(JSON3.write(mtd_dict)))
end
end
end
req_patch = @patch Braket.AWS._http_request(http_backend, request::Braket.AWS.Request, response_stream::IO) = f(http_backend, request, response_stream)
apply(req_patch) do
n_tasks = 10
tasks = [Braket.AwsQuantumTask("arn:fake:$i") for i in 1:n_tasks]
specs = [c for ix in 1:n_tasks]
t = Braket.AwsQuantumTaskBatch(tasks, nothing, Set{String}(), "fake_device", specs, ("fake_bucket", "fake_prefix"), 0, 1, 10)
rs = Braket.results(t)
@test length(rs) == n_tasks
@test all(r isa Braket.GateModelQuantumTaskResult for r in rs)
for r in rs
raw = Braket.format_result(Braket.parse_raw_schema(JSON3.write(mock_result(c))))
@test r.values == raw.values
req_patch = @patch Braket.AWS._http_request(http_backend, request::Braket.AWS.Request, response_stream::IO) = f(http_backend, request, response_stream)
apply(req_patch) do
n_tasks = 10
tasks = [Braket.AwsQuantumTask("arn:fake:$i") for i in 1:n_tasks]
specs = [c for ix in 1:n_tasks]
t = Braket.AwsQuantumTaskBatch(tasks, nothing, Set{String}(), "fake_device", specs, ("fake_bucket", "fake_prefix"), 0, 1, 10)
rs = Braket.results(t)
@test length(rs) == n_tasks
@test all(r isa Braket.GateModelQuantumTaskResult for r in rs)
for r in rs
raw = Braket.format_result(Braket.parse_raw_schema(JSON3.write(mock_result(c))))
@test r.values == raw.values
end
end
end
# test failure
mtd_dict = Dict("status"=>"FAILED", "outputS3Bucket"=>"fake_bucket", "outputS3Directory"=>"fake_dir")
function f(http_backend, request, response_stream)
if request.service == "s3"
return Braket.AWS.Response(Braket.HTTP.Response(200), IOBuffer(JSON3.write(mock_result(c))))
else
return Braket.AWS.Response(Braket.HTTP.Response(200, ["Content-Type"=>"application/json"]), IOBuffer(JSON3.write(mtd_dict)))
@testset "failure" begin
mtd_dict = Dict("status"=>"FAILED", "outputS3Bucket"=>"fake_bucket", "outputS3Directory"=>"fake_dir")
function f(http_backend, request, response_stream)
if request.service == "s3"
return Braket.AWS.Response(Braket.HTTP.Response(200), IOBuffer(JSON3.write(mock_result(c))))
else
return Braket.AWS.Response(Braket.HTTP.Response(200, ["Content-Type"=>"application/json"]), IOBuffer(JSON3.write(mtd_dict)))
end
end
req_patch = @patch Braket.AWS._http_request(http_backend, request::Braket.AWS.Request, response_stream::IO) = f(http_backend, request, response_stream)
apply(req_patch) do
n_tasks = 10
tasks = [Braket.AwsQuantumTask("arn:fake:$i") for i in 1:n_tasks]
specs = [c for ix in 1:n_tasks]
t = Braket.AwsQuantumTaskBatch(tasks, nothing, Set{String}(), "fake_device", specs, ("fake_bucket", "fake_prefix"), 0, 1, 10)
@test_throws ErrorException Braket.results(t, max_retries=0, fail_unsuccessful=true)
@test Braket.results(t, max_retries=0, fail_unsuccessful=false) == fill(nothing, 10)
end
end
req_patch = @patch Braket.AWS._http_request(http_backend, request::Braket.AWS.Request, response_stream::IO) = f(http_backend, request, response_stream)
apply(req_patch) do
@testset "retries" begin
n_tasks = 10
tasks = [Braket.AwsQuantumTask("arn:fake:$i") for i in 1:n_tasks]
specs = [c for ix in 1:n_tasks]
t = Braket.AwsQuantumTaskBatch(tasks, nothing, Set{String}(), "fake_device", specs, ("fake_bucket", "fake_prefix"), 0, 1, 10)
@test_throws ErrorException Braket.results(t, max_retries=0, fail_unsuccessful=true)
@test Braket.results(t, max_retries=0, fail_unsuccessful=false) == fill(nothing, 10)
end
n_tasks = 10
# test retries
new_arns = ["arn:fake:$i" for i in n_tasks+1:2*n_tasks+1]
function f(http_backend, request, response_stream)
if request.service == "s3"
return Braket.AWS.Response(Braket.HTTP.Response(200), IOBuffer(JSON3.write(mock_result(c))))
else
if request.request_method == "POST"
mtd_dict = Dict("quantumTaskArn"=>popfirst!(new_arns), "outputS3Bucket"=>"fake_bucket", "outputS3Directory"=>"fake_dir")
return Braket.AWS.Response(Braket.HTTP.Response(200, ["Content-Type"=>"application/json"]), IOBuffer(JSON3.write(mtd_dict)))
elseif request.request_method == "GET"
mtd_dict = Dict("status"=>"FAILED", "outputS3Bucket"=>"fake_bucket", "outputS3Directory"=>"fake_dir")
return Braket.AWS.Response(Braket.HTTP.Response(200, ["Content-Type"=>"application/json"]), IOBuffer(JSON3.write(mtd_dict)))
# test retries
new_arns = ["arn:fake:$i" for i in n_tasks+1:2*n_tasks+1]
function f(http_backend, request, response_stream)
if request.service == "s3"
return Braket.AWS.Response(Braket.HTTP.Response(200), IOBuffer(JSON3.write(mock_result(c))))
else
if request.request_method == "POST"
mtd_dict = Dict("quantumTaskArn"=>popfirst!(new_arns), "outputS3Bucket"=>"fake_bucket", "outputS3Directory"=>"fake_dir")
return Braket.AWS.Response(Braket.HTTP.Response(200, ["Content-Type"=>"application/json"]), IOBuffer(JSON3.write(mtd_dict)))
elseif request.request_method == "GET"
mtd_dict = Dict("status"=>"FAILED", "outputS3Bucket"=>"fake_bucket", "outputS3Directory"=>"fake_dir")
return Braket.AWS.Response(Braket.HTTP.Response(200, ["Content-Type"=>"application/json"]), IOBuffer(JSON3.write(mtd_dict)))
end
end
end
end
req_patch = @patch Braket.AWS._http_request(http_backend, request::Braket.AWS.Request, response_stream::IO) = f(http_backend, request, response_stream)
apply(req_patch) do
tasks = [Braket.AwsQuantumTask("arn:fake:$i") for i in 1:n_tasks]
specs = [c for ix in 1:n_tasks]
t = Braket.AwsQuantumTaskBatch(tasks, nothing, Set{String}(), "fake_device", specs, ("fake_bucket", "fake_prefix"), 100, 1, 10)
@test Braket.results(t, max_retries=1) == fill(nothing, 10)
req_patch = @patch Braket.AWS._http_request(http_backend, request::Braket.AWS.Request, response_stream::IO) = f(http_backend, request, response_stream)
apply(req_patch) do
tasks = [Braket.AwsQuantumTask("arn:fake:$i") for i in 1:n_tasks]
specs = [c for ix in 1:n_tasks]
t = Braket.AwsQuantumTaskBatch(tasks, nothing, Set{String}(), "fake_device", specs, ("fake_bucket", "fake_prefix"), 100, 1, 10)
@test Braket.results(t, max_retries=1) == fill(nothing, 10)
end
end
end
end

0 comments on commit cfb67a9

Please sign in to comment.