Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: update electronic structure problem with program interface #104

Merged
merged 1 commit into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 101 additions & 8 deletions docs/tutorials/01_quantum_serverless.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
"- building blocks of distributed computation\n",
"- resource allocation and execution management\n",
"- assembling all together\n",
"- electronic structure problem example\n",
"- infrastructure\n",
"- links and references"
"- running as async program"
]
},
{
Expand Down Expand Up @@ -195,13 +193,13 @@
"serverless = QuantumServerless({\"providers\": [...]})\n",
"serverless = QuantumServerless.load_configuration(\"<PATH_TO_CONFIG_FILE>\")\n",
"print(serverless)\n",
"# <QuantumServerless: providers [local, ibm, ...]>\n",
"# <QuantumServerless: providers [local, ibm-cloud, ...]>\n",
"\n",
"with serverless.provider(\"local\"):\n",
" exp_val_execution_reference = exp_val_remote(circuit, obs)\n",
" collected_exp_value = quantum_serverless.get(exp_val_execution_reference)\n",
"\n",
"with serverless.provider(\"ibm\"):\n",
"with serverless.provider(\"ibm-cloud\"):\n",
" exp_val_execution_reference = exp_val_remote(circuit, obs)\n",
" collected_exp_value = quantum_serverless.get(exp_val_execution_reference)\n",
"```"
Expand All @@ -214,20 +212,22 @@
"source": [
"## Assembling all together\n",
"\n",
"Now we have all the important concepts in place and we can assemble our first simple example of a distributed program."
"Now we have all the important concepts in place and we can assemble our first simple example of a distributed program.\n",
"\n",
"> NOTE: make sure to run docker-compose to use this example"
]
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 5,
"id": "6277cbd3-a1ac-4a8f-8a29-c9c92732e780",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[EstimatorResult(values=array([1.]), metadata=[{}]), EstimatorResult(values=array([1.]), metadata=[{}]), EstimatorResult(values=array([-0.8821732]), metadata=[{}])]\n"
"[EstimatorResult(values=array([1.]), metadata=[{}]), EstimatorResult(values=array([1.]), metadata=[{}]), EstimatorResult(values=array([1.]), metadata=[{}])]\n"
]
}
],
Expand Down Expand Up @@ -257,6 +257,99 @@
" \n",
"print(collected_exp_values)"
]
},
{
"cell_type": "markdown",
"id": "a962b872-427d-47c6-9eea-56a53bdfcdc6",
"metadata": {},
"source": [
"## Running as async program\n",
"\n",
"In most of the cases we want to run our scripts as sync programs, so we can lunch them and forget, then later on check results.\n",
"In order to do so we will use `Program` interface.\n",
"\n",
"Let's reuse benchmark script which covers all the concepts covered above and which you can find [here](./source_files/benchmark.py)."
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "75efe890-d7ea-4747-973c-b90e4df9fe39",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2023-01-09 10:42:24,138\tINFO dashboard_sdk.py:362 -- Package gcs://_ray_pkg_521b4aa7701fdb06.zip already exists, skipping upload.\n"
]
},
{
"data": {
"text/plain": [
"<Job | fqs_8c3019a3-d63b-4f22-b91b-338a494ad2e7>"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from quantum_serverless import Program\n",
"\n",
"program = Program(\n",
" name=\"brnchmark_program\",\n",
" entrypoint=\"benchmark.py\",\n",
" working_dir=\"./source_files/\",\n",
" description=\"Benchmark program\"\n",
")\n",
"\n",
"job = serverless.run_program(program)\n",
"job"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "0a7c52b4-c51e-4497-a013-5b1fdc9a5a79",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<JobStatus.RUNNING: 'RUNNING'>"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"job.status()"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "f650750b-4b39-4932-b9dc-a51171d1d146",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'Execution time: 10.197080135345459\\nResults: [[EstimatorResult(values=array([-1.57009246e-16+6.35678836e-17j, 0.00000000e+00+2.00000000e+00j,\\n 1.00000000e+00+4.89879098e-01j, 0.00000000e+00-5.93914329e-01j,\\n 1.00000000e+00+3.84977936e-17j, -3.02888967e-01+0.00000000e+00j,\\n 9.23868961e-01+8.41944092e-01j, -1.00000000e+00-6.98797220e-17j,\\n 9.91094361e-01+5.68284953e-01j, -4.16333634e-17-1.00000000e+00j,\\n 8.07303767e-01+0.00000000e+00j, -5.34510053e-17+0.00000000e+00j,\\n -3.34083829e-01+1.00000000e+00j, 0.00000000e+00+1.65570683e+00j,\\n 8.87382321e-01+0.00000000e+00j, -8.81812854e-01-1.22464680e-16j,\\n -3.08751328e-01-5.78644041e-18j, 0.00000000e+00+1.92837761e-16j,\\n 0.00000000e+00+1.00000000e+00j, 2.00000000e+00+2.58341370e-16j,\\n -1.40395784e-16-8.97966034e-18j, 0.00000000e+00-8.65956056e-17j,\\n -1.22464680e-16-8.72832410e-34j, 1.00000000e+00+0.00000000e+00j,\\n 3.97958431e-01+6.42319385e-01j, -1.00000000e+00+1.00000000e+00j,\\n -1.66533454e-16+9.75159526e-01j, 0.00000000e+00+0.00000000e+00j,\\n -1.00000000e+00-4.83503087e-01j, -9.52623642e-01-5.95841695e-02j]), metadata=[{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}]), EstimatorResult(values=array([-1.57009246e-16+6.35678836e-17j, 0.00000000e+00+2.00000000e+00j,\\n 1.00000000e+00+4.89879098e-01j, 0.00000000e+00-5.93914329e-01j,\\n 1.00000000e+00+3.84977936e-17j, -3.02888967e-01+0.00000000e+00j,\\n 9.23868961e-01+8.41944092e-01j, -1.00000000e+00-6.98797220e-17j,\\n 9.91094361e-01+5.68284953e-01j, -4.16333634e-17-1.00000000e+00j,\\n 8.07303767e-01+0.00000000e+00j, -5.34510053e-17+0.00000000e+00j,\\n -3.34083829e-01+1.00000000e+00j, 0.00000000e+00+1.65570683e+00j,\\n 8.87382321e-01+0.00000000e+00j, -8.81812854e-01-1.22464680e-16j,\\n -3.08751328e-01-5.78644041e-18j, 0.00000000e+00+1.92837761e-16j,\\n 0.00000000e+00+1.00000000e+00j, 2.00000000e+00+2.58341370e-16j,\\n -1.40395784e-16-8.97966034e-18j, 0.00000000e+00-8.65956056e-17j,\\n -1.22464680e-16-8.72832410e-34j, 1.00000000e+00+0.00000000e+00j,\\n 3.97958431e-01+6.42319385e-01j, -1.00000000e+00+1.00000000e+00j,\\n -1.66533454e-16+9.75159526e-01j, 0.00000000e+00+0.00000000e+00j,\\n -1.00000000e+00-4.83503087e-01j, -9.52623642e-01-5.95841695e-02j]), metadata=[{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}]), EstimatorResult(values=array([-1.57009246e-16+6.35678836e-17j, 0.00000000e+00+2.00000000e+00j,\\n 1.00000000e+00+4.89879098e-01j, 0.00000000e+00-5.93914329e-01j,\\n 1.00000000e+00+3.84977936e-17j, -3.02888967e-01+0.00000000e+00j,\\n 9.23868961e-01+8.41944092e-01j, -1.00000000e+00-6.98797220e-17j,\\n 9.91094361e-01+5.68284953e-01j, -4.16333634e-17-1.00000000e+00j,\\n 8.07303767e-01+0.00000000e+00j, -5.34510053e-17+0.00000000e+00j,\\n -3.34083829e-01+1.00000000e+00j, 0.00000000e+00+1.65570683e+00j,\\n 8.87382321e-01+0.00000000e+00j, -8.81812854e-01-1.22464680e-16j,\\n -3.08751328e-01-5.78644041e-18j, 0.00000000e+00+1.92837761e-16j,\\n 0.00000000e+00+1.00000000e+00j, 2.00000000e+00+2.58341370e-16j,\\n -1.40395784e-16-8.97966034e-18j, 0.00000000e+00-8.65956056e-17j,\\n -1.22464680e-16-8.72832410e-34j, 1.00000000e+00+0.00000000e+00j,\\n 3.97958431e-01+6.42319385e-01j, -1.00000000e+00+1.00000000e+00j,\\n -1.66533454e-16+9.75159526e-01j, 0.00000000e+00+0.00000000e+00j,\\n -1.00000000e+00-4.83503087e-01j, -9.52623642e-01-5.95841695e-02j]), metadata=[{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}])]]\\n/home/ray/anaconda3/lib/python3.7/site-packages/ray/_private/worker.py:983: UserWarning: len(ctx) is deprecated. Use len(ctx.address_info) instead.\\n warnings.warn(\"len(ctx) is deprecated. Use len(ctx.address_info) instead.\")\\n'"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"job.logs()"
]
}
],
"metadata": {
Expand Down
Loading