Skip to content

Commit

Permalink
add nec demo (#38)
Browse files Browse the repository at this point in the history
* add nec demo

* black

* black

* black
  • Loading branch information
rryoung98 authored Oct 23, 2024
1 parent 2893a26 commit ce44f22
Showing 1 changed file with 152 additions and 0 deletions.
152 changes: 152 additions & 0 deletions qbraid_sdk/qbraid_runtime_nec.ipynb
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
}

0 comments on commit ce44f22

Please sign in to comment.