Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for result validation; Error in usage example #8

Merged
merged 2 commits into from
Feb 22, 2024
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
46 changes: 24 additions & 22 deletions src/schema.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,24 @@ end
id::String
username::String
email::String
urls::Dict{String, Any}
userType::String="Standard"
urls::Dict{String,Any}
userType::String = "Standard"
firstName::Maybe{String} = nothing
lastName::Maybe{String} = nothing
institution::Maybe{String} = nothing
applications::Vector{String} = String[]
subscriptions::Subscription = Subscription()
readOnly::Bool=false
needsRefill::Bool=false
iqxPreferences::Dict{String, Any} = Dict{String, Any}()
readOnly::Bool = false
needsRefill::Bool = false
iqxPreferences::Dict{String,Any} = Dict{String,Any}()
loginAccounts::Vector{Any} = []
ibmQNetwork::Bool=true
ibmQNetwork::Bool = true
qNetworkRoles::Vector{String} = []
roles::Vector{Any} = []
emailVerified::Bool=false
terms::Dict{String, Any} = Dict{String, Any}()
canScheduleBackends::Bool=true
servicesRoles::Vector{String}=[]
emailVerified::Bool = false
terms::Dict{String,Any} = Dict{String,Any}()
canScheduleBackends::Bool = true
servicesRoles::Vector{String} = []
end

UserInfo(d::AbstractDict{String}) = from_dict(UserInfo, d)
Expand Down Expand Up @@ -139,7 +139,7 @@ the property is false and new tags can be added.
configurable::Bool = false
credits_required::Bool = false
allow_q_object::Bool = false
allow_object_storage::Bool=false
allow_object_storage::Bool = false
n_registers::Maybe{Int} = nothing
open_pulse::Bool = false
quantum_volume::Maybe{Int} = nothing
Expand Down Expand Up @@ -292,11 +292,11 @@ The types of snapshots offered are defined in a separate specification document
for simulators.
"""
@option struct ExpData <: IBMQSchema
counts::Dict{String, Int}
counts::Dict{String,Int}
memory::Maybe{Vector{String}} = nothing
statevector::Maybe{Matrix{ComplexF64}} = nothing
unitary::Maybe{Matrix{ComplexF64}} = nothing
snapshots::Maybe{Dict{String, Any}} = nothing
snapshots::Maybe{Dict{String,Any}} = nothing
end

"""
Expand All @@ -322,11 +322,13 @@ the type of experiment (`"QASM"` or `"PULSE"`) and/or the type of backend (e.g.
simulator data). See below.
"""
@option struct ExpResult <: IBMQSchema
metadata::Maybe{Dict{String, Any}} = nothing
header::Maybe{Dict{String, Any}} = nothing
shots::Union{Int, Vector{Int}}
metadata::Maybe{Dict{String,Any}} = nothing
header::Maybe{Dict{String,Any}} = nothing
shots::Union{Int,Vector{Int}}
status::String
success::Bool
meas_level::Int
circ_id::Int
time_taken::Float64
seed_simulator::Maybe{Int} = nothing
seed::Maybe{Int} = nothing
Expand All @@ -347,8 +349,8 @@ The results data structure from Job.result().
- `results`: List of `m` (number of experiments) exp result data structures (defined below).
"""
@option struct Result <: IBMQSchema
header::Maybe{Dict{String, Any}} = nothing
metadata::Maybe{Dict{String, Any}} = nothing
header::Maybe{Dict{String,Any}} = nothing
metadata::Maybe{Dict{String,Any}} = nothing
time_taken::Maybe{Float64} = nothing
qobj_id::String
job_id::String
Expand Down Expand Up @@ -395,7 +397,7 @@ Abstract type for Qobj schema instructions.
"""
abstract type Instruction <: IBMQSchema end

Configurations.is_option(::Type{T}) where {T <: Instruction} = true
Configurations.is_option(::Type{T}) where {T<:Instruction} = true

"""
struct BooleanFunction <: Instruction
Expand Down Expand Up @@ -517,7 +519,7 @@ experiment. These will override the configuration settings of the whole job. See
- `instructions`: List of sequence commands that define the experiment. See [`Instruction`](@ref).
"""
@option struct Experiment <: IBMQSchema
header::Maybe{Dict{String, Any}} = nothing
header::Maybe{Dict{String,Any}} = nothing
# NOTE: the schema specification didn't mention
# but this can be optional
config::Maybe{ExpConfig} = nothing
Expand Down Expand Up @@ -548,10 +550,10 @@ the backend that the experiments were compiled for.
type::String = "QASM"
schema_version::VersionNumber = v"1.3"
experiments::Vector{Experiment} = Experiment[]
header::Maybe{Dict{String, Any}} = nothing
header::Maybe{Dict{String,Any}} = nothing
config::ExpConfig
end

Configurations.to_dict(::Type{T}, x::VersionNumber) where {T <: IBMQSchema} = string(x)
Configurations.to_dict(::Type{T}, x::VersionNumber) where {T<:IBMQSchema} = string(x)

end
70 changes: 7 additions & 63 deletions test/adapters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ using IBMQClient.Schema
using BrokenRecord

token = "pg3PIrchJpDoyv7cl5GedjE4Q86NuKyriLIIN3SskWMlNDIgnAHALINT8jWgyIdNiEWURUnp2qjr0T4ooP5T60DxejmhbeVFbt1fTeIUlNQPSIbc637GShmhc4xqD65b"

@test IBMQClient.read_token(joinpath(pkgdir(IBMQClient), "test", ".qiskit", "qiskitrc")) == token
BrokenRecord.configure!(path=joinpath(pkgdir(IBMQClient), "test", "records"), ignore_query=["apiToken"], ignore_headers=["X-Access-Token", "apiToken"])

Expand Down Expand Up @@ -51,7 +52,7 @@ end

@test devices[1].backend_name == "ibmq_qasm_simulator"

jobs = playback("jobs.json") do
jobs = playback("jobs.json") do
IBMQClient.jobs(account)
end

Expand All @@ -62,19 +63,19 @@ qobj = Qobj(;
qobj_id="bell_Qobj_07272018",
type="QASM",
schema_version=v"1",
header=Dict("description"=>"Bell states"),
header=Dict("description" => "Bell states"),
config=ExpConfig(shots=1000, memory_slots=2),
experiments=[
Experiment(;
header=Dict("description"=>"|11>+|00> Bell"),
header=Dict("description" => "|11>+|00> Bell"),
instructions=[
Gate(name="u2", qubits=[0], params=[0.0, π]),
Gate(name="cx", qubits=[0, 1]),
Measure(qubits=[0, 1], memory=[0, 1]),
]
),
Experiment(;
header=Dict("description"=>"|01>+|10> Bell"),
header=Dict("description" => "|01>+|10> Bell"),
instructions=[
Gate(name="u2", qubits=[0], params=[0.0, π]),
Gate(name="cx", qubits=[0, 1]),
Expand All @@ -85,6 +86,7 @@ qobj = Qobj(;
]
)


job_info = playback("submit.json") do
IBMQClient.submit(account, RemoteJob(dev=devices[1]), qobj)
end
Expand All @@ -101,63 +103,5 @@ results = playback("result.json") do
IBMQClient.results(account, job_info)
end

@test results.backend_name == "ibmq_qasm_simulator"
@test results.backend_name == "qasm_simulator"
@test results.status == "COMPLETED"

using REPL.TerminalMenus
const CR = "\r"
const LF = "\n"
const UP = "\eOA"
const DOWN = "\eOB"
const ALL = "a"
const NONE = "n"
const DONE = "d"
const SIGINT = "\x03"
const QUIT = "q"

menu = IBMQClient.DeviceMenu(devices)
print(
stdin.buffer,
DOWN,
LF,
CR,
)

choice = request("choose a device:", menu)
@test choice == 2
readavailable(stdin.buffer)

print(
stdin.buffer,
DOWN,
DOWN,
DOWN,
LF,
CR,
)
choice = request("choose a device:", menu)
@test choice == 4
readavailable(stdin.buffer)

print(
stdin.buffer,
DOWN,
DOWN,
DOWN,
QUIT,
)
choice = request("choose a device:", menu)
@test choice == -1
readavailable(stdin.buffer)

@test_throws InterruptException begin
print(
stdin.buffer,
DOWN,
DOWN,
DOWN,
SIGINT,
)
request("choose a device:", menu)
readavailable(stdin.buffer)
end
57 changes: 57 additions & 0 deletions test/menu.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using REPL.TerminalMenus
const CR = "\r"
const LF = "\n"
const UP = "\eOA"
const DOWN = "\eOB"
const ALL = "a"
const NONE = "n"
const DONE = "d"
const SIGINT = "\x03"
const QUIT = "q"

menu = IBMQClient.DeviceMenu(devices)
print(
stdin.buffer,
DOWN,
LF,
CR,
)

choice = request("choose a device:", menu)
@test choice == 2
readavailable(stdin.buffer)

print(
stdin.buffer,
DOWN,
DOWN,
DOWN,
LF,
CR,
)
choice = request("choose a device:", menu)
@test choice == 4
readavailable(stdin.buffer)

print(
stdin.buffer,
DOWN,
DOWN,
DOWN,
QUIT,
)
choice = request("choose a device:", menu)
@test choice == -1
readavailable(stdin.buffer)

@test_throws InterruptException begin
print(
stdin.buffer,
DOWN,
DOWN,
DOWN,
SIGINT,
)
request("choose a device:", menu)
readavailable(stdin.buffer)
end
Loading
Loading