Skip to content

Commit

Permalink
Merge pull request #7 from SpM-lab/sparse-ir
Browse files Browse the repository at this point in the history
Rename irbasis3 to sparse-ir
  • Loading branch information
shinaoka authored Jan 18, 2022
2 parents 75c407e + d4b2a65 commit 2393a28
Show file tree
Hide file tree
Showing 29 changed files with 97 additions and 95 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: irbasis3 python package
name: sparse_ir python package

on: [push]

Expand Down
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
irbasis3 - A library for the intermediate representation of propagators
sparse-ir - A library for the intermediate representation of propagators
=======================================================================
This library provides routines for constructing and working with the
intermediate representation of correlation functions. It provides:
Expand All @@ -10,20 +10,21 @@ intermediate representation of correlation functions. It provides:
Installation
------------

pip install irbasis3 xprec
pip install sparse-ir[xprec]

Though not strictly required, we strongly recommend installing the `xprec`
package alongside `irbasis3` as it allows to compute the IR basis functions
with greater accuracy.
package alongside `sparse-ir` as it allows to compute the IR basis functions
with greater accuracy. If you do not want to do this, simply remove `[xprec]`
from the above line.

Quick start
-----------
Here is some python code illustrating the API:

# Compute IR basis for fermions and β = 10, W <= 4.2
import irbasis3, numpy
K = irbasis3.KernelFFlat(lambda_=42)
basis = irbasis3.FiniteTempBasis(K, statistics='F', beta=10)
import sparse_ir, numpy
K = sparse_ir.KernelFFlat(lambda_=42)
basis = sparse_ir.FiniteTempBasis(K, statistics='F', beta=10)

# Assume spectrum is a single pole at ω = 2.5, compute G(iw)
# on the first few Matsubara frequencies. (Fermionic/bosonic Matsubara
Expand All @@ -32,7 +33,7 @@ Here is some python code illustrating the API:
giw = gl @ basis.uhat([1, 3, 5, 7])

# Reconstruct same coefficients from sparse sampling on the Matsubara axis:
smpl_iw = irbasis3.MatsubaraSampling(basis)
smpl_iw = sparse_ir.MatsubaraSampling(basis)
giw = -1/(1j * numpy.pi/basis.beta * smpl_iw.wn - 2.5)
gl_rec = smpl_iw.fit(giw)

Expand Down
6 changes: 3 additions & 3 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# === Project information

project = 'irbasis3'
project = 'sparse-ir'
copyright = '2021, Markus Wallerberger and others'
author = ', '.join([
'Markus Wallerberger',
Expand All @@ -14,8 +14,8 @@
'Chikano Naoya',
])

release = '3.0-alpha1'
version = '3.0-alpha1'
release = '0.2'
version = '0.2'

# === General configuration

Expand Down
4 changes: 2 additions & 2 deletions doc/hacking.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Hacking/Development
For development, we recommend installing a "editable" version of the
repository with unit test dependencies::

git checkout git@github.com:SpM-lab/irbasis3
cd irbasis3
git checkout git@github.com:SpM-lab/sparse_ir
cd sparse_ir
pip install -e .[test]

Now the installed package automatically updates as you are working on the code.
Expand Down
28 changes: 14 additions & 14 deletions doc/kernels.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@ Kernels
Defines integral kernels for the analytic continuation problem. Specifically,
it defines two kernels:

- `irbasis3.KernelFFlat`: continuation of *fermionic* spectral functions.
- `irbasis3.KernelFFlat`: continuation of *bosonic* spectral functions.
- `sparse_ir.KernelFFlat`: continuation of *fermionic* spectral functions.
- `sparse_ir.KernelFFlat`: continuation of *bosonic* spectral functions.

These can be fed directly into `irbasis3.IRBasis` or `irbasis3.FiniteTempBasis`
These can be fed directly into `sparse_ir.IRBasis` or `sparse_ir.FiniteTempBasis`
to get the intermediate representation.

Predefined kernels
------------------

```{eval-rst}
.. autoclass:: irbasis3.kernel.KernelFFlat
.. autoclass:: sparse_ir.kernel.KernelFFlat
:members:
:special-members: __call__
.. autoclass:: irbasis3.kernel.KernelBFlat
.. autoclass:: sparse_ir.kernel.KernelBFlat
:members:
:special-members: __call__
```

Custom kernels
--------------
Adding kernels to `irbasis3` is simple - at the very basic levle, the library
Adding kernels to `sparse_ir` is simple - at the very basic levle, the library
expects a kernel `K` to be able to provide two things:

1. the values through `K(x, y)`
Expand All @@ -35,13 +35,13 @@ axis instead of the default (flat) one. We create a new kernel by inheriting
from `irbasis.kernel.KernelBase` and then simply wrap around a fermionic
kernel, modifying the values as needed:

import irbasis3
import irbasis3.kernel
import sparse_ir
import sparse_ir.kernel

class KernelFGauss(irbasis3.kernel.KernelBase):
class KernelFGauss(sparse_ir.kernel.KernelBase):
def __init__(self, lambda_, std):
super().__init__(self)
self._inner = irbasis3.KernelFFlat(lambda_)
self._inner = sparse_ir.KernelFFlat(lambda_)
self.lambda_ = lambda_
self.std = std

Expand All @@ -58,7 +58,7 @@ kernel, modifying the values as needed:
You can feed this kernel now directly to `irbasis.IRBasis`:

K = GaussFKernel(10., 1.)
basis = irbasis3.IRBasis(K, 'F')
basis = sparse_ir.IRBasis(K, 'F')
print(basis.s)

This should get you started. For a fully-fledged and robust implementation,
Expand All @@ -82,14 +82,14 @@ Base classes
------------

```{eval-rst}
.. autoclass:: irbasis3.kernel.KernelBase
.. autoclass:: sparse_ir.kernel.KernelBase
:members:
:special-members: __call__
.. autoclass:: irbasis3.kernel.ReducedKernel
.. autoclass:: sparse_ir.kernel.ReducedKernel
:members:
:special-members: __call__
.. autoclass:: irbasis3.kernel.SVEHints
.. autoclass:: sparse_ir.kernel.SVEHints
:members:
```
14 changes: 7 additions & 7 deletions doc/porting.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Porting
=======
For porting codes from irbasis, version 2, to irbasis3, you have two options:
For porting codes from irbasis, version 2, to sparse_ir, you have two options:

* using the `irbasis3.adapter` module (easier)
* porting to the new `irbasis3` API (cleaner)
* using the `sparse_ir.adapter` module (easier)
* porting to the new `sparse_ir` API (cleaner)

In both cases, please note that `irbasis3` now computes the basis on-the-fly
In both cases, please note that `sparse_ir` now computes the basis on-the-fly
rather than loading it from a file. This has some important consequences:

* Singular values and basis functions may slightly differ from the old
Expand All @@ -21,19 +21,19 @@ basis coefficients or store the sampling points together with the data.

Adapter module
--------------
For ease of porting, we provide the `irbasis3.adapter` module. This module
For ease of porting, we provide the `sparse_ir.adapter` module. This module
is API-compatible with the `irbasis` package, version 2. This means you
simply have to replace::

import irbasis

with the following::

import irbasis3.adapter as irbasis
import sparse_ir.adapter as irbasis

and everything should work as expected.

```{eval-rst}
.. autoclass:: irbasis3.adapter.Basis
.. autoclass:: sparse_ir.adapter.Basis
:members:
```
8 changes: 4 additions & 4 deletions doc/sampling.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,20 @@ Sparse sampling transformers
----------------------------

```{eval-rst}
.. autoclass:: irbasis3.sampling.TauSampling
.. autoclass:: sparse_ir.sampling.TauSampling
:members: tau, evaluate, fit
.. autoclass:: irbasis3.sampling.MatsubaraSampling
.. autoclass:: sparse_ir.sampling.MatsubaraSampling
:members: wn, evaluate, fit
```

Base classes
-------------

```{eval-rst}
.. autoclass:: irbasis3.sampling.SamplingBase
.. autoclass:: sparse_ir.sampling.SamplingBase
:members:
.. autoclass:: irbasis3.sampling.DecomposedMatrix
.. autoclass:: sparse_ir.sampling.DecomposedMatrix
:members:
```
14 changes: 7 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ def readfile(*parts):
return f.read()


def extract_varval(*parts, varname):
def extract_varval(varname):
"""Extract value of __version__ variable by parsing python script"""
initfile = readfile(*parts)
var_re = re.compile(r"(?m)^__" + varname + r"__\s*=\s*['\"]([^'\"]*)['\"]")
initfile = readfile('src', 'sparse_ir', '__init__.py')
var_re = re.compile(rf"(?m)^{varname}\s*=\s*['\"]([^'\"]*)['\"]")
match = var_re.search(initfile)
return match.group(1)


VERSION = extract_varval('src', 'irbasis3', '__init__.py', varname='version')
MIN_XPREC_VERSION = extract_varval('src', 'irbasis3', '__init__.py', varname='min_xprec_version')
REPO_URL = "https://github.com/SpM-lab/irbasis3"
REPO_URL = "https://github.com/SpM-lab/sparse-ir"
VERSION = extract_varval('__version__')
MIN_XPREC_VERSION = extract_varval('min_xprec_version')
LONG_DESCRIPTION = readfile('README.md')

setup(
name='irbasis3',
name='sparse-ir',
version=VERSION,

description=
Expand Down
9 changes: 5 additions & 4 deletions src/irbasis3/__init__.py → src/sparse_ir/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
"""
__copyright__ = "Copyright (C) 2020-2021 Markus Wallerberger and others"
__license__ = "MIT"
__version__ = "3.0-alpha6"
__min_xprec_version__ = "1.1.1"
__version__ = "0.2"

min_xprec_version = "1.0"

try:
import xprec as xprec
from pkg_resources import parse_version
from warnings import warn
if parse_version(xprec.__version__) < parse_version(__min_xprec_version__):
warn(f"xprec is too old! Please use xprec>={__min_xprec_version__}.")
if parse_version(xprec.__version__) < parse_version(min_xprec_version):
warn(f"xprec is too old! Please use xprec>={min_xprec_version}.")
except ImportError:
pass

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/irbasis3/adapter.py → src/sparse_ir/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
This is designed to be a drop-in replacement for `irbasis`, where the basis
can be computed on-the-fly for arbitrary values of Lambda. In other words,
you should be able to replace `irbasis` with `irbasis3.adapter` and
you should be able to replace `irbasis` with `sparse_ir.adapter` and
everything should hopefully still work.
Note however that on-the-fly computation typically has lower accuracy. Thus,
Expand Down
File renamed without changes.
12 changes: 6 additions & 6 deletions src/irbasis3/basis.py → src/sparse_ir/basis.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ class IRBasis:
at x = 0.2::
# Compute IR basis suitable for fermions and β*W <= 42
import irbasis3
K = irbasis3.KernelFFlat(lambda_=42)
basis = irbasis3.IRBasis(K, statistics='F')
import sparse_ir
K = sparse_ir.KernelFFlat(lambda_=42)
basis = sparse_ir.IRBasis(K, statistics='F')
# Assume spectrum is a single pole at x = 0.2, compute G(iw)
# on the first few Matsubara frequencies
Expand Down Expand Up @@ -146,9 +146,9 @@ class FiniteTempBasis:
at ω = 2.5::
# Compute IR basis for fermions and β = 10, W <= 4.2
import irbasis3
K = irbasis3.KernelFFlat(lambda_=42)
basis = irbasis3.FiniteTempBasis(K, statistics='F', beta=10)
import sparse_ir
K = sparse_ir.KernelFFlat(lambda_=42)
basis = sparse_ir.FiniteTempBasis(K, statistics='F', beta=10)
# Assume spectrum is a single pole at ω = 2.5, compute G(iw)
# on the first few Matsubara frequencies
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions test/test_augmentation.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Copyright (C) 2020-2021 Markus Wallerberger and others
# SPDX-License-Identifier: MIT
import numpy as np
import irbasis3
from irbasis3 import augmentation
import sparse_ir
from sparse_ir import augmentation
from scipy.special import eval_legendre, spherical_jn

import pytest
Expand Down Expand Up @@ -51,11 +51,11 @@ def test_legendre_basis(stat):
# G(tau) = -e^{-tau*pole}/(1 + e^{-beta*pole}) [F]
# = -e^{-tau*pole}/(1 - e^{-beta*pole}) [B]
pole = 1.0
tau_smpl = irbasis3.TauSampling(basis)
tau_smpl = sparse_ir.TauSampling(basis)
gtau = -np.exp(-tau_smpl.sampling_points * pole)/(1 - sign * np.exp(-beta * pole))
gl_from_tau = tau_smpl.fit(gtau)

matsu_smpl = irbasis3.MatsubaraSampling(basis)
matsu_smpl = sparse_ir.MatsubaraSampling(basis)
giv = 1/(1J*matsu_smpl.sampling_points*np.pi/beta - pole)
gl_from_matsu = matsu_smpl.fit(giv)

Expand Down
2 changes: 1 addition & 1 deletion test/test_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
import pytest

from irbasis3 import adapter
from sparse_ir import adapter

try:
import irbasis
Expand Down
Loading

0 comments on commit 2393a28

Please sign in to comment.