Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
15bb2af
add python-related gigignore
Jan 27, 2026
f5840ea
rename package directory for pypi build
Jan 27, 2026
43de440
add pyproject.toml
Jan 27, 2026
a3f3758
move to scikit-build for future proofing
Jan 27, 2026
1c2a0ef
update README.md
Jan 27, 2026
f20a2b6
modify Documentation path in pyproject.toml
Jan 27, 2026
6aafbdb
flake8 linting in ir.py
Jan 27, 2026
21eaaee
add coverage tool info in pyproject.toml
Jan 27, 2026
2a6f8d1
update codecov.yml for python coverage
Jan 27, 2026
96603e4
python app workflow
Jan 27, 2026
355e191
update import statements in the jupyter-notebook
Jan 27, 2026
2d3ae7f
resolve copilot's reviews
Jan 27, 2026
fef6022
update example ir file to fix failing jupyter cells
Jan 27, 2026
ea4ebb8
update python app workflow file
Jan 27, 2026
62f3d3f
revert back to setuptools
Jan 27, 2026
cfe2fa4
update pytest coverage dependency in python actions
Jan 27, 2026
d3d36ec
Matsubara points should correspond to n not to (2n + \zeta)
iskakoff Feb 7, 2026
98a2a1c
fixed test data + new transformation test
iskakoff Feb 7, 2026
bafc665
rename package directory for pypi build
Jan 27, 2026
7c89ecf
linting changes in ir.py
gauravharsha Feb 8, 2026
468f05f
rename package directory for pypi build
Jan 27, 2026
ae4377e
Merge branch 'main' into pypi
gauravharsha Feb 8, 2026
40cad6b
reintroduce linting in ir.py after rebase
gauravharsha Feb 8, 2026
fdf48b6
update sparse-ir requirements
gauravharsha Feb 8, 2026
6a79353
cleanup
gauravharsha Feb 8, 2026
f510136
revert the change for is None vs empty list
gauravharsha Feb 9, 2026
55bad21
update grid files and add test to check the updates
gauravharsha Feb 9, 2026
9777460
clean up example notebook for github to avoid large image files
gauravharsha Feb 9, 2026
428be3e
fix relative imports and dynamic versioning
gauravharsha Feb 9, 2026
4411ab2
set version to 0.3.0 as a tag for 0.2.4 already exists
gauravharsha Feb 10, 2026
992532f
update grid files for new version info
gauravharsha Feb 10, 2026
8fc39a2
version tags and checks in the C++ src for new grids
gauravharsha Feb 10, 2026
b9a0a08
copilot review - minor fixes
gauravharsha Feb 10, 2026
89a25f0
remove hard-coded version check in ctest
gauravharsha Feb 10, 2026
abfe72e
copilot reviews - better handling of exceptions, better tests, faster…
gauravharsha Feb 11, 2026
0075888
reconfigure not-slow testing; test everything for github actions, but…
gauravharsha Feb 11, 2026
8939977
PyPI build and upload file
gauravharsha Feb 11, 2026
382190f
fix minor things and documentation
gauravharsha Feb 11, 2026
836f80b
remove cibuildwheel options from pyproject.toml - repo is pure python…
gauravharsha Feb 11, 2026
1895141
trigger pypi upload on github release
gauravharsha Feb 11, 2026
59c1048
intuitive function signature for get_version()
gauravharsha Feb 11, 2026
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
4 changes: 3 additions & 1 deletion .github/codecov.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
ignore:
- "test/*"
- "test/*"
- "python/**/tests/**"
- "python/generate.py"
56 changes: 56 additions & 0 deletions .github/workflows/build_wheels.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Build and Publish

on:
push:
branches:
- main
- pypi
tags:
- 'v*'
pull_request:
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build_sdist:
name: Build source distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-python@v5
with:
python-version: '3.x'

- name: Build distributions
run: pipx run build

- uses: actions/upload-artifact@v4
with:
name: sdist
path: dist/*
if-no-files-found: error

upload_pypi:
needs: [build_sdist]
runs-on: ubuntu-latest
environment: release
permissions:
id-token: write
contents: read
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') || github.event_name == 'release'
steps:
- uses: actions/download-artifact@v4
with:
pattern: sdist
path: dist

- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
print-hash: true
48 changes: 48 additions & 0 deletions .github/workflows/python_app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python application

on:
workflow_dispatch:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v4
with:
python-version: "3.12"
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install lcov libhdf5-dev
python -m pip install --upgrade pip
pip install flake8 pytest coverage pytest-cov
pip install -r python/requirements.txt
- name: Lint with flake8
run: |
cd python
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Install package
run: pip install .
- name: Test with pytest
run: pytest --cov python/
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
29 changes: 29 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,32 @@ install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps

# Python related gitignore
__pycache__/
*.pyc
*.pyo
*.pyd
*.egg-info/
dist/
build/
.eggs/
*.egg
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
.ipynb_checkpoints
.pytest_cache/
.tox/
.coverage
htmlcov/
.nox/
.pyre/
.mypy_cache/
.dmypy.json
.pytype/
.pyright/
26 changes: 23 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,35 @@
## Dependencies

- Python:
- Hiroshi's `sparse_ir`
- `numpy`, `scipy`, `h5py`, `mpmath`, ...
- [`sparse-ir`](https://github.com/SpM-lab/sparse-ir)
- `numpy`, `scipy`, `h5py`, and `mpmath`.
- C++:
- Green/h5pp: for compatibility with h5py
- Green/ndarrays: for compatibility with numpy.ndarray
- Green/params: for comandline parameters
- Green/params: for command-line parameters
- CMake: Version 3.27 or later

## Installation

C++ installation uses CMake in a straightforward manner:
```bash
mkdir build && cd build
cmake .. -DCMAKE_INSTALL_PREFIX=.
make -j 4
make install
make test # Test the code
```

The Python package for `green-grids` can be installed using PyPI:
```bash
pip install green-grids
```
or simply by building from source as:
```bash
git clone https://github.com/Green-Phys/green-grids
cd green-grids
pip install .
```

# Acknowledgements

Expand Down
40 changes: 40 additions & 0 deletions c++/green/grids/common_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@
#include <green/ndarray/ndarray.h>
#include <green/ndarray/ndarray_math.h>
#include <green/params/params.h>
#include "except.h"

#include <Eigen/Dense>
#include <cstdio>

using namespace std::string_literals;

namespace green::grids {
// VERSION INFO
inline const std::string GRIDS_MIN_VERSION = "0.2.4";

// NDArray types
template <size_t D>
using itensor = green::ndarray::ndarray<int, D>;
Expand Down Expand Up @@ -48,5 +53,40 @@ namespace green::grids {
}

std::string grid_path(const std::string& path);

/**
* @brief Check whether a version string satisfies the minimum required GRIDS version.
*
* Compares the given version string against the library's minimum supported
* GRIDS version specified by `GRIDS_MIN_VERSION`.
*
* @param v Version string to check (e.g. "0.2.4").
* @return true if v is greater than or equal to GRIDS_MIN_VERSION.
* @return false if v is less than GRIDS_MIN_VERSION.
* @throws outdated_grids_file_error if the format of v or GRIDS_MIN_VERSION is incorrect.
*/
inline bool CheckVersion(const std::string& v) {
int major_Vin = 0, minor_Vin = 0, patch_Vin = 0;
int major_Vref = 0, minor_Vref = 0, patch_Vref = 0;

char suffixV[32] = "";
char suffixM[32] = "";

int parsed_in = std::sscanf(v.c_str(), "%d.%d.%d%30s", &major_Vin, &minor_Vin, &patch_Vin, suffixV);
int parsed_ref = std::sscanf(GRIDS_MIN_VERSION.c_str(), "%d.%d.%d%30s", &major_Vref, &minor_Vref, &patch_Vref, suffixM);

if (parsed_in < 3 || parsed_ref < 3) {
throw outdated_grids_file_error("Version string format is incorrect. Expected format: major.minor.patch[suffix]");
}

if (major_Vin != major_Vref) return major_Vin > major_Vref;
if (minor_Vin != minor_Vref) return minor_Vin > minor_Vref;
if (patch_Vin != patch_Vref) return patch_Vin > patch_Vref;

// If numeric parts in version are all equal, do not worry about suffix
// e.g., 0.2.4b10 has same integral format as 0.2.4
return true;
}

} // namespace green::grids
#endif // GRIDS_COMMON_DEFS_H
5 changes: 5 additions & 0 deletions c++/green/grids/except.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ namespace green::grids {
public:
explicit grids_file_not_found_error(const std::string& string) : runtime_error(string) {}
};

class outdated_grids_file_error : public std::runtime_error {
public:
explicit outdated_grids_file_error(const std::string& string) : runtime_error(string) {}
};
} // namespace green::grids

#endif // GRIDS_EXCEPT_H
19 changes: 18 additions & 1 deletion c++/green/grids/transformer_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,25 @@ namespace green::grids {

sparse_data _sd;

// Version Info
std::string _version = "";

public:
transformer_t(const green::params::params& p) : _sd(p) { read_trans(p["grid_file"]); }
transformer_t(const green::params::params& p) : _sd(p) { read_trans(p["grid_file"]); }

/**
* @brief Set the version string
*
* @param v - std::string
*/
void set_version(const std::string& v) { _version = v; }

/**
* @brief Get the version string
*
* @param v - std::string
*/
const std::string& get_version() const { return _version; }

/**
* @param n - [INPUT] Matsubara frequency number, omega(n) = iw_n
Expand Down
13 changes: 13 additions & 0 deletions c++/transformer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ namespace green::grids {

void transformer_t::read_trans(const std::string& path) {
green::h5pp::archive tnl_file(grid_path(path));

// Read version info
if (tnl_file.has_attribute("__grids_version__")) {
std::string v_str = tnl_file.get_attribute<std::string>("__grids_version__");
set_version(v_str);
if (!CheckVersion(v_str)) {
throw outdated_grids_file_error("The grids file version " + v_str +
" is outdated. Minimum required version is " + GRIDS_MIN_VERSION + ".");
}
} else {
set_version(GRIDS_MIN_VERSION);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about that. If you read file that does not have version why the current version should be set as GRIDS_MIN_VERSION when it is clearly predates GRIDS_MIN_VERSION?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Falling back to 0.2.4 simply to keep a value that is consistent with the previous release tag: https://github.com/Green-Phys/green-grids/releases/tag/v0.2.4

Do you have any alternative suggestion? If we set the grids version to an empty string or, say, "0.0.0", then that will trigger error with green::grids::CheckVersion

}

read_trans_statistics(tnl_file, 1, _Tnc, _Tcn, _Ttc, _Tct);
read_trans_statistics(tnl_file, 0, _Tnc_B, _Tcn_B, _Ttc_B, _Tct_B);

Expand Down
Binary file modified data/cheb/100.h5
Binary file not shown.
Binary file modified data/cheb/150.h5
Binary file not shown.
Binary file modified data/cheb/200.h5
Binary file not shown.
Binary file modified data/cheb/300.h5
Binary file not shown.
Binary file modified data/cheb/350.h5
Binary file not shown.
Binary file modified data/cheb/450.h5
Binary file not shown.
Binary file modified data/ir/1e4.h5
Binary file not shown.
Binary file modified data/ir/1e5.h5
Binary file not shown.
Binary file modified data/ir/1e6.h5
Binary file not shown.
Binary file modified data/ir/1e7.h5
Binary file not shown.
Binary file modified data/ir/1e8.h5
Binary file not shown.
90 changes: 90 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
[build-system]
requires = ["setuptools>=64", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "green-grids"
dynamic = ["version"]
description = "Sparse-grid tools for Green's function methods in physics"
readme = "README.md"
requires-python = ">=3.9"
license = { text = "MIT" } # or your license
authors = [
{ name = "Sergei Iskakov", email = "siskakov@umich.edu" }
]
maintainers = [
{ name = "Gaurav Harsha", email = "gharsha@umich.edu" },
{ name = "Sergei Iskakov", email = "siskakov@umich.edu" }
]
keywords = [
"physics",
"greens-functions",
"sparse-grids",
"numerical-methods",
"many-body",
"scientific-computing"
]
classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Science/Research",
"Topic :: Scientific/Engineering :: Physics",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Operating System :: POSIX",
"Operating System :: Unix",
"Operating System :: MacOS",
]
dependencies = [
"numpy>=1.19.0",
"scipy>=1.5.0",
"h5py>=3.0.0",
"mpmath>=1.0.0",
"sparse-ir>=1.0.0,<2.0.0",
"xprec>=1.3.0"
]

[project.urls]
Homepage = "https://green-phys.org"
Repository = "https://github.com/green-phys/green-grids"
Issues = "https://github.com/green-phys/green-grids/issues"
Documentation = "https://github.com/green-phys/green-grids#readme"

# -------------------------
# setuptools configuration
# -------------------------

[tool.setuptools]
package-dir = {"" = "python"}

[tool.setuptools.packages.find]
where = ["python"]
include = ["green_grids", "green_grids.*"]

[tool.setuptools.dynamic]
version = {attr = "green_grids.version.__version__"}

# -------------------------
# Optional dev tooling
# -------------------------

[project.optional-dependencies]
tests = ["coverage>=5.0.3", "pytest", "pytest-benchmark[histogram]>=3.2.1"]

# -------------------------
# Coverage configuration
# -------------------------
[tool.coverage.run]
branch = true
source = ["python/green_grids"]

# -------------------------
# Pytest configuration
# -------------------------
[tool.pytest.ini_options]
markers = [
"slow: mark a test that takes a long time to run.",
]
Loading