Skip to content

Commit

Permalink
Enable ruff for jupyter notebooks (#147)
Browse files Browse the repository at this point in the history
* Enable ruff for jupyter notebooks

* Fix ruff errors in notebooks
  • Loading branch information
garrison authored Jun 6, 2023
1 parent 9d8aac3 commit 1957a74
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 35 deletions.
3 changes: 3 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ ignore = [
"F405", # star import
"F403", # unable to detect undefined names due to star import
]
"docs/**" = [
"E402", # module level import not at top of file
]
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
"metadata": {},
"outputs": [],
"source": [
"from qiskit_ibm_runtime import QiskitRuntimeService\n",
"from qiskit_ibm_runtime import QiskitRuntimeService # noqa: F401\n",
"\n",
"# Use local versions of the primitives by default.\n",
"service = None\n",
Expand Down Expand Up @@ -573,7 +573,7 @@
}
],
"source": [
"import qiskit.tools.jupyter\n",
"import qiskit.tools.jupyter # noqa: F401\n",
"\n",
"%qiskit_version_table"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
"outputs": [],
"source": [
"from qiskit_ibm_runtime import (\n",
" QiskitRuntimeService,\n",
" QiskitRuntimeService, # noqa: F401\n",
" Options,\n",
")\n",
"\n",
Expand Down Expand Up @@ -242,11 +242,6 @@
"metadata": {},
"outputs": [],
"source": [
"from qiskit_ibm_runtime import (\n",
" QiskitRuntimeService,\n",
" Options,\n",
")\n",
"\n",
"# Use local versions of the primitives by default.\n",
"service = None\n",
"\n",
Expand Down Expand Up @@ -486,7 +481,7 @@
}
],
"source": [
"import qiskit.tools.jupyter\n",
"import qiskit.tools.jupyter # noqa: F401\n",
"\n",
"%qiskit_version_table"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
}
],
"source": [
"from quantum_serverless import QuantumServerless, get\n",
"from quantum_serverless import QuantumServerless\n",
"\n",
"serverless = QuantumServerless()\n",
"serverless.providers()"
Expand Down Expand Up @@ -339,10 +339,7 @@
"metadata": {},
"outputs": [],
"source": [
"from qiskit_ibm_runtime import (\n",
" QiskitRuntimeService,\n",
" Options,\n",
")\n",
"from qiskit_ibm_runtime import QiskitRuntimeService # noqa: F401\n",
"\n",
"# Use local versions of the primitives by default.\n",
"service = None\n",
Expand Down Expand Up @@ -625,7 +622,7 @@
}
],
"source": [
"import qiskit.tools.jupyter\n",
"import qiskit.tools.jupyter # noqa: F401\n",
"\n",
"%qiskit_version_table"
]
Expand Down
12 changes: 2 additions & 10 deletions docs/entanglement_forging/how-tos/freeze-orbitals.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,14 @@
},
"outputs": [],
"source": [
"from matplotlib import pyplot as plt\n",
"import numpy as np\n",
"\n",
"from qiskit.circuit import QuantumCircuit, Parameter\n",
"from qiskit.circuit.library import TwoLocal\n",
"from qiskit.algorithms.optimizers import COBYLA\n",
"from qiskit_nature.second_q.drivers import PySCFDriver\n",
"from qiskit_nature.second_q.problems import ElectronicStructureProblem, ElectronicBasis\n",
"from qiskit_nature.second_q.algorithms import (\n",
" GroundStateEigensolver,\n",
" NumPyMinimumEigensolverFactory,\n",
")\n",
"from qiskit_nature.second_q.problems import ElectronicBasis\n",
"\n",
"from circuit_knitting_toolbox.entanglement_forging import (\n",
" EntanglementForgingAnsatz,\n",
" EntanglementForgingGroundStateSolver,\n",
")\n",
"from circuit_knitting_toolbox.utils import reduce_bitstrings"
]
Expand Down Expand Up @@ -231,7 +223,7 @@
}
],
"source": [
"import qiskit.tools.jupyter\n",
"import qiskit.tools.jupyter # noqa: F401\n",
"\n",
"%qiskit_version_table"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
},
"outputs": [],
"source": [
"from matplotlib import pyplot as plt\n",
"import numpy as np\n",
"\n",
"from qiskit.circuit import QuantumCircuit, Parameter\n",
"from qiskit_nature.second_q.drivers import PySCFDriver\n",
"from qiskit_nature.second_q.hamiltonians import ElectronicEnergy\n",
Expand All @@ -39,7 +36,6 @@
"\n",
"from circuit_knitting_toolbox.entanglement_forging import (\n",
" EntanglementForgingAnsatz,\n",
" EntanglementForgingGroundStateSolver,\n",
")"
]
},
Expand All @@ -63,7 +59,7 @@
"source": [
"# Define a molecular system of interest - Methyl radical\n",
"driver = PySCFDriver(\n",
" atom=f\"C 0.0 0.0 0.0; H 1.0790 0.0 0.0; H -0.5395 -0.9344 0.0; H -0.5395 0.9344 0.0\",\n",
" atom=\"C 0.0 0.0 0.0; H 1.0790 0.0 0.0; H -0.5395 -0.9344 0.0; H -0.5395 0.9344 0.0\",\n",
" spin=1,\n",
")\n",
"problem = driver.run()\n",
Expand Down Expand Up @@ -280,7 +276,7 @@
}
],
"source": [
"import qiskit.tools.jupyter\n",
"import qiskit.tools.jupyter # noqa: F401\n",
"\n",
"%qiskit_version_table"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"source": [
"from qiskit_nature.second_q.drivers import PySCFDriver\n",
"from qiskit_nature.second_q.formats import get_ao_to_mo_from_qcschema\n",
"from qiskit_nature.second_q.problems import ElectronicStructureProblem, ElectronicBasis\n",
"from qiskit_nature.second_q.problems import ElectronicBasis\n",
"\n",
"driver = PySCFDriver(\"H 0.0 0.0 0.0; H 0.0 0.0 0.735\")\n",
"driver.run()\n",
Expand Down Expand Up @@ -124,7 +124,7 @@
"metadata": {},
"outputs": [],
"source": [
"from qiskit_ibm_runtime import QiskitRuntimeService, Options\n",
"from qiskit_ibm_runtime import QiskitRuntimeService, Options # noqa: F401\n",
"\n",
"# By default, use a local simulator to implement the Qiskit Runtime Primitives\n",
"service = None\n",
Expand Down Expand Up @@ -311,7 +311,7 @@
}
],
"source": [
"import qiskit.tools.jupyter\n",
"import qiskit.tools.jupyter # noqa: F401\n",
"\n",
"%qiskit_version_table"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@
}
],
"source": [
"import qiskit.tools.jupyter\n",
"import qiskit.tools.jupyter # noqa: F401\n",
"\n",
"%qiskit_version_table"
]
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ style = [
"autoflake==2.1.1",
"black[jupyter]==23.3.0",
"ruff>=0.0.246",
"nbqa>=1.6.0",
]
lint = [
"circuit-knitting-toolbox[style]",
Expand Down
2 changes: 2 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ extras =
style
commands =
ruff check --fix circuit_knitting_toolbox/ docs/ test/ tools/
nbqa ruff --fix docs/
autoflake --in-place --recursive circuit_knitting_toolbox/ docs/ test/ tools/
black circuit_knitting_toolbox/ docs/ test/ tools/

Expand All @@ -24,6 +25,7 @@ extras =
lint
commands =
ruff check circuit_knitting_toolbox/ docs/ test/ tools/
nbqa ruff docs/
autoflake --check --quiet --recursive circuit_knitting_toolbox/ docs/ test/ tools/
black --check circuit_knitting_toolbox/ docs/ test/ tools/
pydocstyle circuit_knitting_toolbox/
Expand Down

0 comments on commit 1957a74

Please sign in to comment.