Skip to content

Commit

Permalink
Update notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
pedromxavier committed Oct 12, 2023
1 parent 8e7f36b commit 44d1641
Show file tree
Hide file tree
Showing 2 changed files with 5,632 additions and 622 deletions.
133 changes: 38 additions & 95 deletions notebooks/4-DWave.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -238,41 +238,13 @@
"We can visualize the graph that defines this instance using the Q matrix as the adjacency matrix of a graph."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"using Graphs"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{11, 58} undirected simple Int64 graph"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"G = SimpleGraph(Q)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"using Karnak"
"using Plots"
]
},
{
Expand Down Expand Up @@ -471,18 +443,7 @@
}
],
"source": [
"@drawsvg(\n",
" begin\n",
" sethue(\"black\")\n",
" background(\"white\")\n",
" drawgraph(\n",
" G;\n",
" margin = 80,\n",
" vertexlabels = 1:11,\n",
" )\n",
" end,\n",
" 400, 400\n",
")"
"plot(QUBOTools.SystemLayoutPlot(Q))"
]
},
{
Expand Down Expand Up @@ -558,7 +519,7 @@
"source": [
"using JuMP\n",
"using QUBO\n",
"using DWaveNeal"
"using DWave"
]
},
{
Expand Down Expand Up @@ -621,7 +582,8 @@
}
],
"source": [
"set_optimizer(qubo_model, DWaveNeal.Optimizer)\n",
"# Use D-Wave's simulated annealer 'Neal'\n",
"set_optimizer(qubo_model, DWave.Neal.Optimizer)\n",
"\n",
"set_optimizer_attribute(qubo_model, \"num_reads\", 1_000)\n",
"\n",
Expand All @@ -630,15 +592,6 @@
"println(\"Minimum energy: $(objective_value(qubo_model))\")"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"using Plots"
]
},
{
"cell_type": "code",
"execution_count": 14,
Expand Down Expand Up @@ -801,7 +754,7 @@
}
],
"source": [
"QUBOTools.sampleset(unsafe_backend(qubo_model)) |> plot"
"plot(QUBOTools.EnergyFrequencyPlot(qubo_model))"
]
},
{
Expand Down Expand Up @@ -831,15 +784,6 @@
"ENV[\"DWAVE_API_TOKEN\"] = \"<YOUR_KEY_HERE>\";"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"using DWave"
]
},
{
"cell_type": "code",
"execution_count": 16,
Expand All @@ -854,6 +798,7 @@
}
],
"source": [
"# Use D-Wave's quantum annealer\n",
"set_optimizer(qubo_model, DWave.Optimizer)\n",
"\n",
"set_optimizer_attribute(qubo_model, \"num_reads\", 1024)\n",
Expand Down Expand Up @@ -1855,7 +1800,16 @@
}
],
"source": [
"QUBOTools.sampleset(unsafe_backend(qubo_model)) |> plot"
"plot(QUBOTools.EnergyFrequencyPlot(qubo_model))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"using Graphs"
]
},
{
Expand All @@ -1875,46 +1829,35 @@
"outputs": [],
"source": [
"function get_topology(sampler)\n",
" qpu_edges = sampler.edgelist\n",
" qpu_nodes = sampler.nodelist\n",
"\n",
" println(\"Solver ID = '$(sampler.solver.id)'\")\n",
" println(\"Number of qubits = $(length(qpu_nodes))\")\n",
" println(\"Number of couplers = $(length(qpu_edges))\")\n",
"\n",
" if string(sampler.solver.id) == \"DW_2000Q_6\"\n",
" χ = DWave.dwave_networkx.chimera_graph(16, node_list=qpu_nodes, edge_list=qpu_edges)\n",
"\n",
" return (χ, :chimera)\n",
" return DWave.dwave_networkx.chimera_graph(\n",
" 16,\n",
" node_list=sampler.nodelist,\n",
" edge_list=sampler.edgelist,\n",
" )\n",
" elseif string(sampler.solver.id) == \"Advantage_system1.1\"\n",
" χ = DWave.dwave_networkx.pegasus_graph(16, node_list=qpu_nodes, edge_list=qpu_edges)\n",
" \n",
" return (χ, :pegasus)\n",
" return DWave.dwave_networkx.pegasus_graph(\n",
" 16,\n",
" node_list=sampler.nodelist,\n",
" edge_list=sampler.edgelist,\n",
" )\n",
" elseif string(sampler.solver.id) == \"Advantage_system4.1\"\n",
" χ = DWave.dwave_networkx.pegasus_graph(16, node_list=qpu_nodes, edge_list=qpu_edges)\n",
" \n",
" return (χ, :pegasus)\n",
" return DWave.dwave_networkx.pegasus_graph(\n",
" 16,\n",
" node_list=sampler.nodelist,\n",
" edge_list=sampler.edgelist,\n",
" )\n",
" else\n",
" @warn \"Unknown solver id '$(sampler.solver.id)'\"\n",
" error(\"Unknown solver id '$(sampler.solver.id)'\")\n",
"\n",
" return (nothing, nothing)\n",
" return nothing\n",
" end\n",
"end\n",
"\n",
"function draw_topology(sampler)\n",
" χ, arch = get_topology(sampler)\n",
" χ = get_topology(sampler)\n",
"\n",
" if arch === nothing\n",
" return nothing\n",
" elseif arch === :chimera\n",
" # @time DWave.dwave_networkx.draw_chimera(χ, node_size=1)\n",
" return nothing # DWave.plt.show()\n",
" elseif arch === :pegasus\n",
" # @time DWave.dwave_networkx.draw_pegasus(χ, node_size=1)\n",
" return nothing # DWave.plt.show()\n",
" else\n",
" return nothing\n",
" end\n",
" g = Graphs.grpah\n",
"end\n",
"\n",
"draw_topology(sampler)"
Expand Down Expand Up @@ -2078,15 +2021,15 @@
],
"metadata": {
"kernelspec": {
"display_name": "Julia 1.9.1",
"display_name": "Julia 1.9.3",
"language": "julia",
"name": "julia-1.9"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.9.1"
"version": "1.9.3"
},
"orig_nbformat": 4
},
Expand Down
Loading

0 comments on commit 44d1641

Please sign in to comment.