-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
143 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "c74a8efa-92a9-4728-95c1-09351bbff90c", | ||
"metadata": {}, | ||
"source": [ | ||
"# Quantum Vertex Cover" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "c0dd6b02-4c8b-4aed-93fa-78463b1a60e2", | ||
"metadata": {}, | ||
"source": [ | ||
"Dynex is the world’s only accessible neuromorphic quantum computing cloud for solving real-world problems, at scale.. This example demonstrates how to use the Dynex SDK to use Pyton to compute on the Dynex Platform with Python." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"id": "3f4f5809-e324-43ff-b680-f3a411b53f58", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import dynex\n", | ||
"import dimod\n", | ||
"from qubovert.problems import VertexCover" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "b5dfc1be-7afc-42ba-b4b8-f01508a8c1f6", | ||
"metadata": {}, | ||
"source": [ | ||
"The goal of the VertexCover problem is to find the smallest number of verticies that can be colored such that every edge of the graph is incident to a colored vertex." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"id": "87a5132a-a36e-4d0f-bbc0-c13cc4da44cb", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"edges = {(\"a\", \"b\"), (\"a\", \"c\"), (\"c\", \"d\"), (\"a\", \"d\")}\n", | ||
"problem = VertexCover(edges)\n", | ||
"Q = problem.to_qubo()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"id": "7d55a452-c115-482d-b6a5-c3f84da4088d", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"bqm = dimod.BinaryQuadraticModel.from_qubo(Q.Q, Q.offset)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"id": "58ce0834-dfb2-4499-8db6-e61b51c8b7dd", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"[DYNEX] PRECISION SET TO 0.0001\n", | ||
"[DYNEX] SAMPLER INITIALISED\n", | ||
"[DYNEX|TESTNET] *** WAITING FOR READS ***\n", | ||
"╭────────────┬──────────┬─────────────────┬─────────────┬───────────┬───────────────────────────┬────────────┬─────────┬────────────────╮\n", | ||
"│ DYNEXJOB │ QUBITS │ QUANTUM GATES │ BLOCK FEE │ ELAPSED │ WORKERS READ │ CIRCUITS │ STEPS │ GROUND STATE │\n", | ||
"├────────────┼──────────┼─────────────────┼─────────────┼───────────┼───────────────────────────┼────────────┼─────────┼────────────────┤\n", | ||
"│ -1 │ 12 │ 16 │ 0 │ │ *** WAITING FOR READS *** │ │ │ │\n", | ||
"╰────────────┴──────────┴─────────────────┴─────────────┴───────────┴───────────────────────────┴────────────┴─────────┴────────────────╯\n", | ||
"\n", | ||
"[DYNEX] FINISHED READ AFTER 0.32 SECONDS\n", | ||
"[DYNEX] SAMPLESET READY\n", | ||
" 0 1 2 3 energy num_oc.\n", | ||
"0 1 0 0 1 2.0 1\n", | ||
"['BINARY', 1 rows, 1 samples, 4 variables]\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"sampleset = dynex.sample(bqm, mainnet=False, num_reads=1024, annealing_time=200);\n", | ||
"print(sampleset)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"id": "977fe637-057c-4993-a427-caa0b3ed52ab", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Optimal solution: {'d', 'a'} valid? True\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"solution = problem.convert_solution(sampleset.first.sample)\n", | ||
"print('Optimal solution:',solution,'valid?',problem.is_solution_valid(solution))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "8053b159-7735-4fe2-a3b1-01a68aea21ff", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.10.12" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |