Skip to content
Open
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
35 changes: 35 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Lint check

on:
push:
branches:
- main
- 'stable/**'
pull_request:
branches:
- main
- 'stable/**'

jobs:
lint:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v7
with:
# reno reads the notes from git history, so `reno lint` needs more than a
# shallow clone. The submodule the tests need is not checked out: the lint
# environment sets `skip_install`, so nothing here compiles the extension.
fetch-depth: 0
- name: Set up Python 3.11
uses: actions/setup-python@v7
with:
python-version: '3.11'
- name: Install tox
run: |
python -m pip install --upgrade pip
pip install tox
- name: Run lint check
shell: bash
run: |
tox -elint
28 changes: 14 additions & 14 deletions examples/tpb/run_sbd_diag.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def parse_args():
description='Quantum chemistry calculation with CPU/GPU support',
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)

# Device selection
parser.add_argument('--device',
choices=['auto', 'cpu',
Expand All @@ -68,7 +68,7 @@ def parse_args():
'gpu-omp (nvc++ OpenMP target offload) | auto. '
'gpu-nvhpc-omp / gpu-nvidia-omp are deprecated '
'aliases for gpu-omp.')

# Input files
parser.add_argument('--fcidump', default='../../vendor/sbd-upstream/data/h2o/fcidump.txt',
help='Path to FCIDUMP file')
Expand All @@ -84,15 +84,15 @@ def parse_args():
help='Load initial wavefunction from file')
parser.add_argument('--savename', default='',
help='Save final wavefunction to file')

# MPI communicator sizes
parser.add_argument('--adet_comm_size', type=int, default=1,
help='Alpha determinant communicator size')
parser.add_argument('--bdet_comm_size', type=int, default=1,
help='Beta determinant communicator size')
parser.add_argument('--task_comm_size', type=int, default=1,
help='Helper communicator size')

# Diagonalization method and convergence
parser.add_argument('--method', type=int, default=0, choices=[0, 1, 2, 3],
help='Diagonalization method: 0=Davidson, 1=Davidson+Ham, 2=Lanczos, 3=Lanczos+Ham')
Expand All @@ -104,7 +104,7 @@ def parse_args():
help='Convergence tolerance')
parser.add_argument('--max_time', type=float, default=1e10,
help='Maximum time in seconds')

# Initialization and options
parser.add_argument('--init', type=int, default=0,
help='Starting vector. 0 puts unit weight on the FIRST '
Expand Down Expand Up @@ -147,11 +147,11 @@ def parse_args():
help='Carryover ratio')
parser.add_argument('--carryover_threshold', '--threshold', type=float, default=0.0, dest='threshold',
help='Carryover threshold')

# Determinant representation
parser.add_argument('--bit_length', type=int, default=20,
help='Bit length for determinant representation')

# Output options
parser.add_argument('--dump_matrix_form_wf', default='',
help='Filename to dump wavefunction in matrix form')
Expand All @@ -162,13 +162,13 @@ def parse_args():
parser.add_argument('--max_memory_gb_for_determinants', '--gpu-memory', type=int, default=-1,
dest='max_memory_gb_for_determinants',
help='Maximum GPU memory in GB for determinants (-1=auto, GPU only)')

return parser.parse_args()


def main():
args = parse_args()

# Import sbd — auto-initializes on first use, but we call init()
# explicitly here to set the default device from --device flag.
import sbd
Expand All @@ -178,14 +178,14 @@ def main():

rank = sbd.get_rank()
size = sbd.get_world_size()

if rank == 0:
print("="*70)
print("SBD Simplified API - Chemistry Calculation")
print("="*70)
sbd.print_info()
print()

# Configure calculation
config = sbd.TPB_SBD()
config.max_it = args.max_it
Expand All @@ -211,12 +211,12 @@ def main():
config.use_precalculated_dets = bool(args.use_precalculated_dets)
if hasattr(config, 'max_memory_gb_for_determinants'):
config.max_memory_gb_for_determinants = args.max_memory_gb_for_determinants

if rank == 0:
print("Configuration:")
print(f" Device: {sbd.get_device()}")
print(f" Communication: {sbd.get_comm_backend()}")
print(f" Method: Davidson")
print(" Method: Davidson")
print(f" Max iterations: {config.max_it}")
print(f" Tolerance: {config.eps}")
print(f" MPI ranks: {size}")
Expand All @@ -231,7 +231,7 @@ def main():
f"requires task x adet x bdet x helper == ranks exactly, so this "
f"will abort in TaskCommunicator with 'MPI Size of twister is not "
f"a square of a integer'. Use a multiple of {_grid} ranks.")
print(f"\nInput files:")
print("\nInput files:")
print(f" FCIDUMP: {args.fcidump}")
print(f" Alpha dets: {args.adetfile}")
print()
Expand Down
5 changes: 3 additions & 2 deletions examples/tpb/run_sqd_sbd.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@
],
"source": [
"from functools import partial\n",
"import json, numpy as np\n",
"import json\n",
"import numpy as np\n",
"from pathlib import Path\n",
"from mpi4py import MPI\n",
"from pyscf import ao2mo, tools\n",
Expand Down Expand Up @@ -517,7 +518,7 @@
"\n",
"print()\n",
"print(f'Final SQD energy: {result.energy + nuc:.10f} Ha (electronic {result.energy:.10f} + nuc {nuc:.6f})')\n",
"print(f'FCI reference : ≈ −76.24 Ha')"
"print('FCI reference : ≈ −76.24 Ha')"
]
},
{
Expand Down
92 changes: 92 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ notebook-dependencies = [
"pyscf>=2.9",
]

[dependency-groups]
# The linters live in dependency groups rather than optional-dependencies: they are
# never installed alongside the package (the lint envs set `skip_install`), so there is
# no reason to publish them as extras in the wheel metadata.
style = [
"ruff==0.16.9",
]
lint = [
{include-group = "style"},
"reno>=4.1",
]

[project.urls]
Homepage = "https://github.com/Qiskit/sbd-eigensolver-python"
Documentation = "https://github.com/Qiskit/sbd-eigensolver-python"
Expand All @@ -76,6 +88,86 @@ packages = ["sbd"]
package-dir = {sbd = "python"}
zip-safe = false

[tool.ruff]
line-length = 100
src = ["python", "test"]
target-version = "py311"

[tool.ruff.lint]
select = [
"I", # isort
"E", # pycodestyle
"W", # pycodestyle
"D", # pydocstyle
"F", # pyflakes
"RUF", # ruff
"UP", # pyupgrade
"SIM", # flake8-simplify
"B", # flake8-bugbear
"A", # flake8-builtins
]
ignore = [
"E501", # line too long
]

[tool.ruff.lint.extend-per-file-ignores]
"test/**.py" = [
"D", # pydocstyle
]
"docs/**/*" = [
"E402", # module level import not at top of file
"D", # pydocstyle
]
# The examples are written to be read top to bottom, so their helpers carry an
# explanatory comment rather than a docstring, and the prose uses the same
# mathematical symbols (alpha, the minus sign, the multiplication sign) as the
# surrounding discussion.
"examples/**/*" = [
"D", # pydocstyle
"I001", # unsorted-imports: see the isort note below
"RUF001", # ambiguous unicode character in string
"RUF003", # ambiguous unicode character in comment
"SIM102", # collapsible if: the nesting mirrors the explanation
]
# `i, j, k, l` is the FCIDUMP two-electron integral index order, so `l` here is
# the name the file format uses rather than an ambiguous identifier.
"python/sbd_solver.py" = [
"E741", # ambiguous variable name
]
# `__all__` is grouped by topic with comments, which sorting would flatten.
"python/__init__.py" = [
"RUF022", # `__all__` is not sorted
]

[tool.ruff.lint.isort]
# The package directory is `python/` but it imports as `sbd` (see
# `[tool.setuptools] package-dir`), so isort cannot infer that `sbd` is ours and
# would otherwise group it with the third-party imports.
#
# This makes `sbd` its own import group, which isort separates with a blank line.
# That is what we want in `python/` and `test/`, but in the examples it splits
# short function-local blocks like `from mpi4py import MPI` next to `import sbd`
# for no gain, so `I001` is ignored for `examples/` above.
known-first-party = ["sbd"]

[tool.ruff.lint.pydocstyle]
convention = "google"

[tool.ruff.lint.flake8-copyright]
notice-rgx = """
# This code is a Qiskit project.
#
# \\(C\\) Copyright IBM \\d{4}((,\\s)\\d{4})*\\.
#
# This code is licensed under the Apache License, Version 2\\.0\\. You may
# obtain a copy of this license in the LICENSE\\.txt file in the root directory
# of this source tree or at http\\:\\/\\/www\\.apache\\.org\\/licenses\\/LICENSE\\-2\\.0\\.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals\\.
"""

[tool.pytest.ini_options]
testpaths = ["test"]
# -rs lists the skipped tests and why, which matters here because most of the suite
Expand Down
Loading
Loading