Skip to content

Commit

Permalink
Merge pull request #3 from QuantumApplicationLab/lint
Browse files Browse the repository at this point in the history
Lint
  • Loading branch information
NicoRenaud authored May 5, 2023
2 parents 72b5a52 + f4993ab commit 94ca585
Show file tree
Hide file tree
Showing 26 changed files with 649 additions and 601 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test_development_versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
strategy:
max-parallel: 4
matrix:
python-version: [3.7, '3.10']
python-version: [3.8, '3.10']
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test_latest_versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ jobs:
max-parallel: 4
matrix:
os: [ubuntu-latest]
python-version: [3.7, 3.8, 3.9, '3.10']
python-version: [3.8, 3.9, '3.10']
include:
- os: macos-latest
python-version: 3.7
python-version: 3.8
- os: windows-latest
python-version: 3.7
python-version: 3.8
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test_minimum_versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
max-parallel: 4
matrix:
python-version: [3.7]
python-version: [3.8]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand Down
6 changes: 3 additions & 3 deletions docs/apidocs/index.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.. vqls:
.. vqls_prototype:
.. module:: vqls
.. module:: vqls_prototype

=============================
Template API References
Expand All @@ -9,4 +9,4 @@ Template API References
.. toctree::
:maxdepth: 1

vqls
vqls_prototype
4 changes: 0 additions & 4 deletions docs/apidocs/template.rst

This file was deleted.

4 changes: 4 additions & 0 deletions docs/apidocs/vqls_prototype.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.. automodule:: vqls_prototype
:no-members:
:no-inherited-members:
:no-special-members:
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
_rootdir = Path(__file__).parent.parent

# The full version, including alpha/beta/rc tags
release = metadata_version("prototype_template")
release = metadata_version("vqls_prototype")
# The short X.Y version
version = ".".join(release.split(".")[:2])

Expand Down
26 changes: 12 additions & 14 deletions docs/how_tos/01_how_to_solve_linear_system.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"size = 4\n",
"\n",
"# matrix of the linear system\n",
"A = np.random.rand(size,size)\n",
"A = np.random.rand(size, size)\n",
"A = A + A.T\n",
"\n",
"# right hand side of the linear system\n",
Expand Down Expand Up @@ -77,9 +77,10 @@
],
"source": [
"from qiskit.circuit.library.n_local.real_amplitudes import RealAmplitudes\n",
"\n",
"nqbit = int(np.log2(size))\n",
"ansatz = RealAmplitudes(nqbit, entanglement=\"full\", reps=3, insert_barriers=False)\n",
"ansatz.decompose().draw('mpl')"
"ansatz.decompose().draw(\"mpl\")"
]
},
{
Expand All @@ -101,22 +102,17 @@
"outputs": [],
"source": [
"from vqls_prototype import VQLS, VQLSLog\n",
"from qiskit.primitives import Estimator \n",
"from qiskit.primitives import Estimator\n",
"from qiskit.algorithms import optimizers as opt\n",
"\n",
"# instantiate an estimator primitive\n",
"estimator = Estimator()\n",
"\n",
"# create a logger \n",
"log = VQLSLog([],[])\n",
"# create a logger\n",
"log = VQLSLog([], [])\n",
"\n",
"# create the vqls solver\n",
"vqls = VQLS(\n",
" estimator,\n",
" ansatz,\n",
" opt.CG(maxiter=200),\n",
" callback=log.update \n",
")"
"vqls = VQLS(estimator, ansatz, opt.CG(maxiter=200), callback=log.update)"
]
},
{
Expand Down Expand Up @@ -188,9 +184,10 @@
],
"source": [
"import matplotlib.pyplot as plt\n",
"\n",
"plt.semilogy(log.values)\n",
"plt.ylabel('Cost Function')\n",
"plt.xlabel('Iterations')"
"plt.ylabel(\"Cost Function\")\n",
"plt.xlabel(\"Iterations\")"
]
},
{
Expand All @@ -212,6 +209,7 @@
"outputs": [],
"source": [
"from qiskit.quantum_info import Statevector\n",
"\n",
"vqls_solution = np.real(Statevector(res.state).data)"
]
},
Expand Down Expand Up @@ -252,7 +250,7 @@
}
],
"source": [
"ref_solution = np.linalg.solve(A, b/np.linalg.norm(b))\n",
"ref_solution = np.linalg.solve(A, b / np.linalg.norm(b))\n",
"ref_solution = ref_solution / np.linalg.norm(ref_solution)\n",
"\n",
"plt.scatter(ref_solution, vqls_solution)\n",
Expand Down
17 changes: 6 additions & 11 deletions docs/how_tos/02_how_to_use_circuits.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@
"qc1 = QuantumCircuit(nqbit)\n",
"qc1.x(0)\n",
"qc1.x(1)\n",
"qc1.cnot(0,1)\n",
"qc1.cnot(0, 1)\n",
"\n",
"# second quantum circuit for A\n",
"qc2 = QuantumCircuit(nqbit)\n",
"qc2.h(0)\n",
"qc2.x(1)\n",
"qc2.cnot(0,1)\n",
"qc2.cnot(0, 1)\n",
"\n",
"# quantum circuit for b\n",
"rhs = QuantumCircuit(nqbit)\n",
Expand All @@ -93,7 +93,7 @@
"outputs": [],
"source": [
"from vqls_prototype import VQLS, VQLSLog\n",
"from qiskit.primitives import Estimator \n",
"from qiskit.primitives import Estimator\n",
"from qiskit.algorithms import optimizers as opt\n",
"from qiskit.circuit.library.n_local.real_amplitudes import RealAmplitudes\n",
"\n",
Expand All @@ -103,16 +103,11 @@
"# instantiate an estimator primitive\n",
"estimator = Estimator()\n",
"\n",
"# create a logger \n",
"log = VQLSLog([],[])\n",
"# create a logger\n",
"log = VQLSLog([], [])\n",
"\n",
"# create the vqls solver\n",
"vqls = VQLS(\n",
" estimator,\n",
" ansatz,\n",
" opt.CG(maxiter=200),\n",
" callback=log.update \n",
")"
"vqls = VQLS(estimator, ansatz, opt.CG(maxiter=200), callback=log.update)"
]
},
{
Expand Down
45 changes: 23 additions & 22 deletions docs/how_tos/03_how_to_use_runtime.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"nqbit = int(np.log2(size))\n",
"\n",
"# matrix of the linear system\n",
"A = np.random.rand(size,size)\n",
"A = np.random.rand(size, size)\n",
"A = A + A.T\n",
"\n",
"# right hand side of the linear system\n",
Expand Down Expand Up @@ -69,33 +69,34 @@
"from vqls_prototype import VQLS, VQLSLog\n",
"from qiskit.algorithms import optimizers as opt\n",
"\n",
"# start the runtime service\n",
"service = QiskitRuntimeService()\n",
"backend = \"simulator_statevector\"\n",
"# make sure your IBMQ account is saved\n",
"\n",
"# start session\n",
"with Session(service=service, backend=backend) as session:\n",
"try:\n",
" # start the runtime service\n",
" service = QiskitRuntimeService()\n",
" backend = \"simulator_statevector\"\n",
"\n",
" # options of the primitives\n",
" options = Options()\n",
" options.optimization_level = 3\n",
" # start session\n",
" with Session(service=service, backend=backend) as session:\n",
" # options of the primitives\n",
" options = Options()\n",
" options.optimization_level = 3\n",
"\n",
" # estimator \n",
" estimator = Estimator(session=session, options=options)\n",
" # estimator\n",
" estimator = Estimator(session=session, options=options)\n",
"\n",
" # log\n",
" log = VQLSLog([],[]) \n",
" # log\n",
" log = VQLSLog([], [])\n",
"\n",
" # declare the solver\n",
" vqls = VQLS(\n",
" estimator,\n",
" ansatz,\n",
" optimizer=opt.CG(maxiter=200),\n",
" callback=log.update\n",
" )\n",
" # declare the solver\n",
" vqls = VQLS(\n",
" estimator, ansatz, optimizer=opt.CG(maxiter=200), callback=log.update\n",
" )\n",
"\n",
" # solve the linear system\n",
" solution = vqls.solve(A, b)\n"
" # solve the linear system\n",
" solution = vqls.solve(A, b)\n",
"except:\n",
" print(\"make sure you have a valid IBMQ account saved\")"
]
}
],
Expand Down
44 changes: 25 additions & 19 deletions docs/how_tos/04_how_to_control_options.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"nqbit = int(np.log2(size))\n",
"\n",
"# matrix of the linear system\n",
"A = np.random.rand(size,size)\n",
"A = np.random.rand(size, size)\n",
"A = A + A.T\n",
"\n",
"# right hand side of the linear system\n",
Expand All @@ -56,15 +56,17 @@
"metadata": {},
"outputs": [],
"source": [
"from vqls_prototype import VQLS, VQLSLog\n",
"from qiskit.primitives import Estimator, Sampler\n",
"from qiskit.algorithms import optimizers as opt\n",
"from vqls_prototype import VQLS, VQLSLog\n",
"\n",
"# instantiate an estimator primitive\n",
"estimator, sampler, log = Estimator(), Sampler(), VQLSLog([],[])\n",
"estimator, sampler, log = Estimator(), Sampler(), VQLSLog([], [])\n",
"\n",
"# create the vqls solver\n",
"vqls = VQLS(estimator,ansatz,opt.CG(maxiter=200),callback=log.update,sampler=sampler)"
"vqls = VQLS(\n",
" estimator, ansatz, opt.CG(maxiter=200), callback=log.update, sampler=sampler\n",
")"
]
},
{
Expand All @@ -85,9 +87,11 @@
"metadata": {},
"outputs": [],
"source": [
"opt= {\"use_overlap_test\": ... ,\n",
" \"use_local_cost_function\": ...,\n",
" \"matrix_decomposition\": ... }"
"opt = {\n",
" \"use_overlap_test\": ...,\n",
" \"use_local_cost_function\": ...,\n",
" \"matrix_decomposition\": ...,\n",
"}"
]
},
{
Expand Down Expand Up @@ -137,9 +141,10 @@
}
],
"source": [
"from vqls_prototype import PauliDecomposition \n",
"from vqls_prototype import PauliDecomposition\n",
"\n",
"pauli_decomposition = PauliDecomposition(A)\n",
"pauli_decomposition.circuits[5].draw('mpl')"
"pauli_decomposition.circuits[5].draw(\"mpl\")"
]
},
{
Expand Down Expand Up @@ -185,9 +190,10 @@
}
],
"source": [
"from vqls_prototype import SymmetricDecomposition \n",
"from vqls_prototype import SymmetricDecomposition\n",
"\n",
"symmetric_decomposition = SymmetricDecomposition(A)\n",
"symmetric_decomposition.circuits[0].decompose().draw('mpl')"
"symmetric_decomposition.circuits[0].decompose().draw(\"mpl\")"
]
},
{
Expand Down Expand Up @@ -247,9 +253,9 @@
}
],
"source": [
"options = vqls._validate_solve_options({\"use_overlap_test\":False})\n",
"options = vqls._validate_solve_options({\"use_overlap_test\": False})\n",
"_, qc_test = vqls.construct_circuit(A, b, options)\n",
"qc_test[0].circuits[0].decompose().draw('mpl')"
"qc_test[0].circuits[0].decompose().draw(\"mpl\")"
]
},
{
Expand Down Expand Up @@ -283,9 +289,9 @@
}
],
"source": [
"options = vqls._validate_solve_options({\"use_overlap_test\":True})\n",
"options = vqls._validate_solve_options({\"use_overlap_test\": True})\n",
"_, qc_test = vqls.construct_circuit(A, b, options)\n",
"qc_test[0].circuits[0].decompose().draw('mpl')"
"qc_test[0].circuits[0].decompose().draw(\"mpl\")"
]
},
{
Expand Down Expand Up @@ -334,9 +340,9 @@
}
],
"source": [
"options = vqls._validate_solve_options({\"use_local_cost_function\":False})\n",
"options = vqls._validate_solve_options({\"use_local_cost_function\": False})\n",
"_, qc_test = vqls.construct_circuit(A, b, options)\n",
"qc_test[0].circuits[0].decompose().draw('mpl')"
"qc_test[0].circuits[0].decompose().draw(\"mpl\")"
]
},
{
Expand Down Expand Up @@ -370,9 +376,9 @@
}
],
"source": [
"options = vqls._validate_solve_options({\"use_local_cost_function\":True})\n",
"options = vqls._validate_solve_options({\"use_local_cost_function\": True})\n",
"_, qc_test = vqls.construct_circuit(A, b, options)\n",
"qc_test[0].circuits[0].decompose().draw('mpl')"
"qc_test[0].circuits[0].decompose().draw(\"mpl\")"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Template project documentation
##############################

This template repository makes creating new quantum prototype projects much easier for our team. It reduces the overhead of implementing the "bones" of a project -- including package setup, testing, and CI/CD. The code examples in this template repository are written in accordance with pylint style checks, and the sample prototype_template module has an associated unit test module. We have also included examples of coverage testing, notebook tests, and notebook lint checks and wrapped all of these using tox automated testing software.
This template repository makes creating new quantum prototype projects much easier for our team. It reduces the overhead of implementing the "bones" of a project -- including package setup, testing, and CI/CD. The code examples in this template repository are written in accordance with pylint style checks, and the sample vqls_prototype module has an associated unit test module. We have also included examples of coverage testing, notebook tests, and notebook lint checks and wrapped all of these using tox automated testing software.

.. toctree::
:maxdepth: 1
Expand Down
Loading

0 comments on commit 94ca585

Please sign in to comment.