Skip to content

Commit

Permalink
Add JSON treatment to dwave info output
Browse files Browse the repository at this point in the history
  • Loading branch information
pedromxavier committed Nov 29, 2023
1 parent b2840e7 commit a9bf1a8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
24 changes: 13 additions & 11 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
name = "DWave"
uuid = "4d534982-bf11-4157-9e48-fe3a62208a50"
name = "DWave"
uuid = "4d534982-bf11-4157-9e48-fe3a62208a50"
authors = ["pedromxavier <[email protected]>", "pedroripper <[email protected]>"]
version = "0.4.2"
version = "0.4.3"

[deps]
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
PythonCall = "6099a3de-0909-46bc-b1f4-468b9a2dfc0d"
QUBODrivers = "a3f166f7-2cd3-47b6-9e1e-6fbfe0449eb0"
QUBOTools = "60eb5b62-0a39-4ddc-84c5-97d2adff9319"
PythonCall = "6099a3de-0909-46bc-b1f4-468b9a2dfc0d"
QUBODrivers = "a3f166f7-2cd3-47b6-9e1e-6fbfe0449eb0"
QUBOTools = "60eb5b62-0a39-4ddc-84c5-97d2adff9319"

[compat]
Graphs = "1"
Graphs = "1"
JSON = "0.21"
MathOptInterface = "1"
PythonCall = "0.9.15"
QUBODrivers = "0.3"
QUBOTools = "0.9"
julia = "1.9"
PythonCall = "0.9.15"
QUBODrivers = "0.3"
QUBOTools = "0.9"
julia = "1.9"
10 changes: 10 additions & 0 deletions src/DWave.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module DWave

import Graphs
import JSON
import QUBOTools
import QUBODrivers
import MathOptInterface as MOI
Expand All @@ -9,6 +10,7 @@ using PythonCall

# -*- :: Python D-Wave Module :: -*- #
const np = PythonCall.pynew()
const json = PythonCall.pynew()
const dwave_cloud = PythonCall.pynew()
const dwave_dimod = PythonCall.pynew()
const dwave_embedding = PythonCall.pynew()
Expand All @@ -33,6 +35,7 @@ end
function __init__()
# Python Packages
PythonCall.pycopy!(np, pyimport("numpy"))
PythonCall.pycopy!(json, pyimport("json"))
PythonCall.pycopy!(dwave_cloud, pyimport("dwave.cloud"))
PythonCall.pycopy!(dwave_dimod, pyimport("dimod"))
PythonCall.pycopy!(dwave_embedding, pyimport("dwave.embedding"))
Expand All @@ -44,6 +47,13 @@ function __init__()
return nothing
end

function jl_object(py_obj)
# Convert Python object to JSON string, then parse it into a Julia object
data = pyconvert(String, json.dumps(py_obj))

return JSON.parse(data)
end

include("sampler.jl")
include("neal/sampler.jl")

Expand Down
2 changes: 1 addition & 1 deletion src/sampler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function QUBODrivers.sample(sampler::Optimizer{T}) where {T}
"time" => Dict{String,Any}( #
"effective" => results.time,
),
"dwave_info" => results.value.info
"dwave_info" => jl_object(results.value.info)
)

return QUBOTools.SampleSet{T,Int}(samples, metadata; sense = :min, domain = :spin)
Expand Down

0 comments on commit a9bf1a8

Please sign in to comment.