Skip to content

Commit

Permalink
Pre commit (#143)
Browse files Browse the repository at this point in the history
* add precommits

* use philipps precommit config

* add ruff config to prproject

* lint with pre-commits

* changelog

* changelog

* poetry lock

* add pytest cov
  • Loading branch information
MIWdlB authored Dec 26, 2024
1 parent b26168b commit 023ea78
Show file tree
Hide file tree
Showing 29 changed files with 1,417 additions and 1,291 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ jobs:
continue-on-error: True
- name: Testing
run: |
poetry run pytest
poetry run pytest
4 changes: 2 additions & 2 deletions .github/workflows/push_to_master.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Push to Master CICD
on:
on:
push:
branches:
- master
Expand Down Expand Up @@ -34,4 +34,4 @@ jobs:
continue-on-error: True
- name: Testing
run: |
poetry run pytest
poetry run pytest
6 changes: 3 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
continue-on-error: True
- name: Testing
run: |
poetry run pytest
poetry run pytest
publish:
runs-on: ubuntu-latest
needs: build
Expand All @@ -49,6 +49,6 @@ jobs:
poetry config repositories.testpypi https://test.pypi.org/legacy/
poetry build
- name: Publish to testpypi
run: poetry publish -r testpypi --skip-existing -u ${{secrets.PYPI_USERNAME}} -p ${{secrets.TESTPYPI_PASSWORD}}
run: poetry publish -r testpypi --skip-existing -u ${{secrets.PYPI_USERNAME}} -p ${{secrets.TESTPYPI_PASSWORD}}
- name: Publish to pypi
run: poetry publish -u ${{secrets.PYPI_USERNAME}} -p ${{secrets.PYPI_PASSWORD}}
run: poetry publish -u ${{secrets.PYPI_USERNAME}} -p ${{secrets.PYPI_PASSWORD}}
31 changes: 31 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: check-yaml
args: ["--unsafe"]
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/asottile/pyupgrade
rev: v3.19.0
hooks:
- id: pyupgrade
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.7.0
hooks:
# Run the linter.
- id: ruff
types_or: [python, pyi, jupyter]
args: [--fix]
# Run the formatter.
- id: ruff-format
types_or: [python, pyi, jupyter]
- repo: https://github.com/gitleaks/gitleaks
rev: v8.21.1
hooks:
- id: gitleaks
- repo: https://github.com/python-poetry/poetry
rev: '1.8.5'
hooks:
- id: poetry-check
4 changes: 2 additions & 2 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ build:
# # Install dependencies with 'docs' dependency group
# # https://python-poetry.org/docs/managing-dependencies/#dependency-groups
# - poetry install --with docs


# Build documentation in the docs/ directory with Sphinx
sphinx:
Expand All @@ -45,4 +45,4 @@ sphinx:
# python:
# install:
# - method: pip
# path: .
# path: .
13 changes: 9 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## Added
- `.pre-commit-config.yaml` added

## Changed
- python version requirement changed to `>=3.9, <4`

## [0.0.7]
### Changed
Expand All @@ -28,7 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added
- `get_hartree_fock_state` function in `HamBuilder`
- `run_qmmm`, `mm_coords`, `mm_charges`, `mm_radii` and `symmetry` attributes for NbedDriver.
- `run_qmmm`, `mm_coords`, `mm_charges`, `mm_radii` and `symmetry` attributes for NbedDriver.

### Deprecated
- `HamBuilder.build` has `taper` bool input, but the main way to do this is now the `Symmer.QubitReductionDriver`
Expand All @@ -49,7 +54,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- `frozen` option for FCI calls CASSCF
- `driver.cl_shells` attribute assigned when concentric localization is run
- `SpadeLocalizer.singular_values` and `.shells` properties
- `SpadeLocalizer.singular_values` and `.shells` properties

## [0.0.3]
### Fixed
Expand Down Expand Up @@ -87,7 +92,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0


## [0.0.1] - 2022-03-07
### Fixed
### Fixed
- `NbedDriver._init_local_rhf` reversion which used the old `local_basis_transform`
### Added
- Basic functionality for initial release
Expand All @@ -96,4 +101,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- DOI button from zenodo in readme
- DOI added to citation file
### Changed
- LISCENCE.txt changed to LICENSE.md
- LISCENCE.txt changed to LICENSE.md
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ authors:
title: "Nbed"
version: 0.0.7
date-released: 2022-03-07
doi: 10.5281/zenodo.6323338
doi: 10.5281/zenodo.6323338
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ This virtual environment subsequently can be activated with:
poetry shell
## Use

The package has three main interfaces, each to the same function `embed/nbed`.
The package has three main interfaces, each to the same function `embed/nbed`.

### Importing the package
This function is accessable by importing the package into a python file.
Expand Down Expand Up @@ -155,4 +155,4 @@ Contains all tests of the package. These can be run from the command line using
Each time the package is initialised a new log will be started in the top level director at `Nbed/.nbed.log`.

## Development
If you would like to contribute to this code base please first create an issue and a fork of the repo from which to make your pull request.
If you would like to contribute to this code base please first create an issue and a fork of the repo from which to make your pull request.
2 changes: 1 addition & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
contain the root `toctree` directive.
.. uncomment and add to toctree when ready
.. notebooks/A Scalable Approach to Quantum Simulation via Projection-based Embedding
.. notebooks/A Scalable Approach to Quantum Simulation via Projection-based Embedding
Welcome to Nbed's documentation!
================================

Expand Down
8 changes: 5 additions & 3 deletions nbed/ham_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ def _spinorb_from_spatial(
# Loop through integrals.
for p in range(n_qubits // 2):
for q in range(n_qubits // 2):

# Populate 1-body coefficients. Require p and q have same spin.
one_body_coefficients[2 * p, 2 * q] = one_body_integrals[0, p, q]
one_body_coefficients[2 * p + 1, 2 * q + 1] = one_body_integrals[
Expand All @@ -275,7 +274,6 @@ def _spinorb_from_spatial(
# Assumes 2e ints are ordered as aaaa,bbbb,aabb,bbaa.
for r in range(n_qubits // 2):
for s in range(n_qubits // 2):

# Same spin
two_body_coefficients[2 * p, 2 * q, 2 * r, 2 * s] = (
two_body_integrals[0, p, q, r, s]
Expand Down Expand Up @@ -481,7 +479,7 @@ def fermion_to_qubit_operator(
Note: see `openfermion.transforms` for different fermion to qubit mappings
Args:
Fermionic_operator(FermionOperator): any fermionic operator (openfermion)
fermionic_operator (FermionOperator): any fermionic operator (openfermion)
n_qubits (int): number of qubits (or spin orbitals)
Returns:
Expand All @@ -495,6 +493,9 @@ def fermion_to_qubit_operator(
def to_openfermion(pwop: PauliwordOp) -> QubitOperator:
"""Convert to OpenFermion Pauli operator representation.
Args:
pwop (PauliwordOp): The PauliwordOp to convert.
Returns:
open_f (QubitOperator): The QubitOperator representation of the PauliwordOp.
"""
Expand All @@ -504,6 +505,7 @@ def symplectic_to_of(symp_vec, coeff) -> str:
Args:
symp_vec (array): symplectic Pauliword array
coeff (float): coefficient of the Pauliword
Returns:
Pword_string (str): String version of symplectic array
Expand Down
2 changes: 1 addition & 1 deletion nbed/ham_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def _read_file(self, filepath) -> Dict[str, float]:
filepath (Path): Path to a .json file containing the IR.
"""
logger.debug("Reading IR from file.")
with open(filepath, "r") as file:
with open(filepath) as file:
file_data = json.load(file)

self.n_qubits = file_data["qubits"]
Expand Down
3 changes: 2 additions & 1 deletion nbed/localizers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def localize_virtual(
Args:
local_scf (StreamObject): SCF object with occupied orbitals localized.
cutoff (float | int): Cutoff for localizing virtual orbitals.
Returns:
StreamObject: Fully Localized SCF object.
Expand Down Expand Up @@ -194,7 +195,7 @@ def _check_values(self) -> None: # Needs clarification

if warn_flag:
logger.error("Localizer sense check failed.")
raise NbedLocalizerError(f"Localizer sense check failed.\n")
raise NbedLocalizerError("Localizer sense check failed.\n")
else:
logger.debug("Localizer sense check passed.")

Expand Down
4 changes: 2 additions & 2 deletions nbed/mol_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ def draw_cube_orbital(
else:
raise ValueError(f"unknown py3dmol style: {style}")

with open(File_name, "r") as f:
with open(File_name) as f:
view.addVolumetricData(
f.read(), "cube", {"isoval": -0.02, "color": "red", "opacity": 0.75}
)
with open(File_name, "r") as f2:
with open(File_name) as f2:
view.addVolumetricData(
f2.read(), "cube", {"isoval": 0.02, "color": "blue", "opacity": 0.75}
)
Expand Down
9 changes: 4 additions & 5 deletions nbed/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ def restricted_float_percentage(x: float) -> float:
try:
x = float(x)
except ValueError:
raise argparse.ArgumentTypeError("%r not a floating-point literal" % (x,))
raise argparse.ArgumentTypeError("{!r} not a floating-point literal".format(x))

if x < 0.0 or x > 1.0:
raise argparse.ArgumentTypeError("%r not in range [0.0, 1.0]" % (x,))
raise argparse.ArgumentTypeError("{!r} not in range [0.0, 1.0]".format(x))
return x


Expand Down Expand Up @@ -212,7 +212,7 @@ def parse():
if args.config:
logger.debug("Reading config file.")
filepath = Path(args.config).absolute()
stream = open(filepath, "r")
stream = open(filepath)
args = yaml.safe_load(stream)["nbed"]

# Optional argument defaults
Expand Down Expand Up @@ -432,8 +432,7 @@ def build_ordered_xyz_string(struct_dict: dict, active_atom_inds: list) -> str:
Returns:
xyz_string (str): raw xyz string of molecular geometry (atoms ordered by atom_ordering_by_inds list)
Example
Example:
input_struct_dict = { 0: ('O', (0, 0, 0)),
1: ('H', (0.2774, 0.8929, 0.2544)),
2: ('H', (0.6068, -0.2383, -0.7169))
Expand Down
Loading

0 comments on commit 023ea78

Please sign in to comment.