Skip to content

Code and style updates on Python files #1645

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
6 changes: 3 additions & 3 deletions client/qiskit_serverless/core/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,9 @@ def fetch_meta(circuit: QuantumCircuit) -> CircuitMeta:
elif isinstance(argument, list):
for sub_idx, sub_argument in enumerate(argument):
if isinstance(sub_argument, QuantumCircuit):
meta[
f"{OT_ATTRIBUTE_PREFIX}.args.arg_{idx}.{sub_idx}"
] = fetch_meta(sub_argument).to_seq()
meta[f"{OT_ATTRIBUTE_PREFIX}.args.arg_{idx}.{sub_idx}"] = (
fetch_meta(sub_argument).to_seq()
)
for key, value in kwargs.items():
if isinstance(value, QuantumCircuit):
meta[f"{OT_ATTRIBUTE_PREFIX}.kwargs.{key}"] = fetch_meta(value).to_seq()
Expand Down
1 change: 1 addition & 0 deletions client/tests/core/test_pattern.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests jobs."""

import os

from testcontainers.compose import DockerCompose
Expand Down
1 change: 1 addition & 0 deletions client/tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test utils."""

import time

from ray.dashboard.modules.job.sdk import JobSubmissionClient
Expand Down
9 changes: 1 addition & 8 deletions docs/deployment/custom_function/runner.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@


class Runner:
def run(self, arguments: dict) -> dict:
return {
**arguments,
**{
"answer": 42
}
}
return {**arguments, **{"answer": 42}}
138 changes: 28 additions & 110 deletions docs/examples/01_vqe.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -117,42 +117,27 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'ansatz': <qiskit.circuit.library.n_local.efficient_su2.EfficientSU2 at 0x7f8ee8de92b0>,\n",
" 'operator': SparsePauliOp(['YZ', 'ZI', 'ZZ', 'XX'],\n",
" coeffs=[ 0.398 +0.j, -0.398 +0.j, -0.0113+0.j, 0.181 +0.j]),\n",
" 'method': 'COBYLA',\n",
" 'service': None}"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"import numpy as np\n",
"\n",
"\n",
"from qiskit.circuit.library import EfficientSU2\n",
"from qiskit.quantum_info import SparsePauliOp\n",
"\n",
"from qiskit_ibm_runtime import QiskitRuntimeService, Estimator, Session, Options\n",
"from qiskit_ibm_runtime import QiskitRuntimeService\n",
"\n",
"USE_RUNTIME_SERVICE = False\n",
"\n",
"service = None\n",
"if USE_RUNTIME_SERVICE:\n",
" service = QiskitRuntimeService(\n",
" channel='ibm_quantum',\n",
" instance='ibm-q/open/main',\n",
" token='<Your Token>',\n",
" verify=False\n",
" channel=\"ibm_quantum\",\n",
" instance=\"ibm-q/open/main\",\n",
" token=\"<Your Token>\",\n",
" verify=False,\n",
" )\n",
"\n",
"operator = SparsePauliOp.from_list(\n",
Expand All @@ -179,7 +164,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -189,20 +174,9 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<ServerlessProvider: gateway-provider>"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"serverless = ServerlessClient(\n",
" token=os.environ.get(\"GATEWAY_TOKEN\", \"awesome_token\"),\n",
Expand All @@ -213,114 +187,58 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'vqe'"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"from qiskit_serverless import QiskitFunction\n",
"\n",
"if USE_RUNTIME_SERVICE:\n",
" function = QiskitFunction(title=\"vqe\", entrypoint=\"vqe.py\", working_dir=\"./source_files/vqe/\")\n",
" function = QiskitFunction(\n",
" title=\"vqe\", entrypoint=\"vqe.py\", working_dir=\"./source_files/vqe/\"\n",
" )\n",
"else:\n",
" function = QiskitFunction(title=\"vqe\", entrypoint=\"vqe.py\", working_dir=\"./source_files/vqe/\", dependencies=[\"qiskit_aer\"])\n",
" function = QiskitFunction(\n",
" title=\"vqe\",\n",
" entrypoint=\"vqe.py\",\n",
" working_dir=\"./source_files/vqe/\",\n",
" )\n",
"\n",
"serverless.upload(function)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<Job | 94ae450e-bb6f-46c3-a0b0-1ad12b91115f>"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"job = serverless.run(\"vqe\", arguments=input_arguments)\n",
"job"
]
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'QUEUED'"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"job.status()"
]
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'result': {'0': 0.4223, '1': 0.3604, '2': 0.1073, '3': 0.11},\n",
" 'optimal_point': [2.51762813907937,\n",
" 1.532634671366952,\n",
" 6.968201754881848,\n",
" 1.8258529400009142,\n",
" 1.5453234923701027,\n",
" 3.905921764150066,\n",
" 1.6694898480396192,\n",
" 1.075020301957671,\n",
" 0.8048376424004327,\n",
" 2.823196594205023,\n",
" 2.9665234835014846,\n",
" 4.143832547893007,\n",
" 4.382722375425133,\n",
" 4.582108812661252,\n",
" 6.596830693043498,\n",
" 4.716678649450963],\n",
" 'optimal_value': -0.7029303910686284,\n",
" 'optimizer_time': 3.4171429999987595}"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"job.result()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": ".venv_serverless",
"language": "python",
"name": "python3"
},
Expand All @@ -334,7 +252,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.16"
"version": "3.11.9"
}
},
"nbformat": 4,
Expand Down
Loading
Loading