-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: q3as in default use case template (#105)
* feat: q3as in default use case template * chore: add caution message for user cred * fix: make q3as as demo and not solution * fix: use env var for q3as secrets * chore: add .env file for loading q3as secrets * chore: add .env to submission template --------- Co-authored-by: Julian Popescu <[email protected]>
- Loading branch information
1 parent
b55bf69
commit e2203c8
Showing
7 changed files
with
148 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
!assets/**/* |
File renamed without changes.
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,13 @@ | ||
# Keep your secrets safe here and load with python-dotenv | ||
|
||
# Q3AS API Key | ||
# --- | ||
# Start by visiting https://q3as.aqora.io and signing in with your GitHub or Google account. | ||
# Click on your profile in the top right and go to API Keys. | ||
# Tap Add API Key and enter a description for your API key. | ||
# Copy your id and secret and paste them here | ||
|
||
Q3AS_ID="<your_q3as_id>" | ||
Q3AS_SECRET="<your_q3as_secret>" | ||
|
||
# --- |
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 |
---|---|---|
|
@@ -53,3 +53,6 @@ docs/_build/ | |
.aqora | ||
.venv | ||
__aqora__/ | ||
|
||
# environment | ||
.env |
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
123 changes: 123 additions & 0 deletions
123
template/assets/use_case/template/submission/q3as_demo.ipynb
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,123 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Getting an API Key\n", | ||
"\n", | ||
"To run your algorithms in the cloud, you have to create an API key and load it into your Credentials\n", | ||
"\n", | ||
"Start by visiting https://q3as.aqora.io and signing in with your GitHub or Google account. Click on your profile in the top right and go to API Keys. Tap Add API Key and enter a description for your API key. Tap Copy id and secret and paste them into the [`env`](../.env) file. " | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from q3as import Client, Credentials\n", | ||
"from dotenv import load_dotenv\n", | ||
"import os\n", | ||
"\n", | ||
"load_dotenv()\n", | ||
"\n", | ||
"id = os.getenv(\"Q3AS_ID\")\n", | ||
"secret = os.getenv(\"Q3AS_SECRET\")\n", | ||
"\n", | ||
"client = Client(Credentials(id=id, secret=secret))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"From here we can start building out the definition of the problem that we would like to solve. We'll start with an NP Hard problem called Maximum Weighted Cut. We can define a graph we would like to cut by supplying a list of edges and their weights." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"graph = [\n", | ||
" (0, 1, 1.0),\n", | ||
" (0, 2, 1.0),\n", | ||
" (0, 4, 1.0),\n", | ||
" (1, 2, 1.0),\n", | ||
" (2, 3, 1.0),\n", | ||
" (3, 4, 1.0),\n", | ||
"]" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"We can then give this graph to our \"Application\" which will define what we want to do with it and how to translate it into the quantum world and back. Q3AS defines multiple such problem domains that you can use" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from q3as.app import Maxcut\n", | ||
"\n", | ||
"app = Maxcut(graph)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"We now need to define a solver for our problem. We will use a Variational Quantum Eigensolver or VQE for short" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from q3as import VQE\n", | ||
"\n", | ||
"vqe = VQE.builder().app(app)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Now we can send the job to the Q3AS, and let the server handle the computation and the visualization of the intermediate results" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"job = vqe.send(client)\n", | ||
"# get the name of the job\n", | ||
"print(job.name)\n", | ||
"# wait for and retrieve the results of the job\n", | ||
"print(job.result())\n", | ||
"# get the problem cost\n", | ||
"print(job.result().cost)\n", | ||
"# see job in the dashbaord\n", | ||
"print(\"https://q3as.aqora.io/jobs/\" + job.name)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"language_info": { | ||
"name": "python" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |