-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add nec demo * black * black * black
- Loading branch information
Showing
1 changed file
with
152 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# qBraid SDK NEC integration\n", | ||
"\n", | ||
"The [qBraid-SDK](https://github.com/qBraid/qBraid) is platform-agnostic quantum runtime framework. Distinguishing itself through a streamlined and highly-configurable approach to cross-platform integration, the qBraid-SDK does not assume a fixed target software framework. Instead, it allows providers to dynamically register any desired run input program type as the target, depending on their specific needs.\n", | ||
"\n", | ||
"This notebook demonstrates how to use the qBraid-SDK to run a qubo on the NEC backend." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"%%capture\n", | ||
"\n", | ||
"# First, we install the essential libraries to our current Python runtime.\n", | ||
"# \"%%capture\" (above) captures and in this case, hides the output of this\n", | ||
"# cell, so you can comment it out if you need help debugging this step.\n", | ||
"\n", | ||
"%pip install 'qbraid[runtime]' matplotlib pyqubo" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from qbraid.runtime import QbraidProvider" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"provider = QbraidProvider()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"<DeviceStatus.ONLINE: 'online'>" | ||
] | ||
}, | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"device = provider.get_device(\"nec_vector_annealer\")\n", | ||
"\n", | ||
"device.status()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"<ProgramSpec('cpp_pyqubo.Model', 'cpp_pyqubo')>" | ||
] | ||
}, | ||
"execution_count": 7, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"target_spec = device.profile.get(\"program_spec\")\n", | ||
"\n", | ||
"target_spec" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 8, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"{'solutions': [{'spin': {'s1': 0, 's2': 0, 's3': 1, 's4': 0}, 'energy': 0, 'time': 0.005164086818695068, 'constraint': True, 'memory_usage': 1.189453125}], 'num_solutions': 1}\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# Insert your qbraid API key, in the form of a string, below.\n", | ||
"# If you have the correct permission, you will be able to\n", | ||
"# access the NEC Vector Annealer through the Qbraid Runtime.\n", | ||
"from pyqubo import Spin\n", | ||
"\n", | ||
"from qbraid import QbraidProvider\n", | ||
"\n", | ||
"s1, s2, s3, s4 = Spin(\"s1\"), Spin(\"s2\"), Spin(\"s3\"), Spin(\"s4\")\n", | ||
"H = (4 * s1 + 2 * s2 + 7 * s3 + s4) ** 2\n", | ||
"model = H.compile()\n", | ||
"qubo, offset = model.to_qubo()\n", | ||
"\n", | ||
"provider = QbraidProvider(api_key=\"YOUR_API_KEY\")\n", | ||
"device = provider.get_device(\"nec_vector_annealer\")\n", | ||
"\n", | ||
"params = {\n", | ||
" \"offset\": offset,\n", | ||
" \"num_reads\": 10,\n", | ||
"}\n", | ||
"\n", | ||
"job = device.run(model, params=params)\n", | ||
"result = job.result()\n", | ||
"print(result.data.to_dict())" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "qbraid2", | ||
"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.11.9" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |