Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
Use pre-build builds for metatensor
Browse files Browse the repository at this point in the history
  • Loading branch information
PicoCentauri committed Oct 17, 2023
1 parent ddf12d8 commit 5581630
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 33 deletions.
8 changes: 1 addition & 7 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
ase
matplotlib
furo
# Since the metatensor version hash in rascaline might be two old for equisolve,
# we load a specific branch that has the same metatensor hash as we are using
# here.
#
# When we update the metatensor hash here we ALSO have to update the hash
# in the rascaline branch!
rascaline @ https://github.com/luthaf/rascaline/archive/23448bd.zip
rascaline @ https://github.com/luthaf/rascaline/archive/581d0ca.zip
sphinx >=4.4
sphinx-gallery
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ keywords = [
requires-python = ">=3.7"

dependencies = [
"metatensor @ https://github.com/lab-cosmo/metatensor/archive/2248a3c.zip",
"metatensor",
"numpy",
"scipy",
"skmatter"
]
[project.optional-dependencies]
torch = ["metatensor[torch] @ https://github.com/lab-cosmo/metatensor/archive/2248a3c.zip"]
torch = ["metatensor[torch]"]

[project.urls]
homepage = "https://lab-cosmo.github.io/equisolve/latest/"
Expand Down
6 changes: 3 additions & 3 deletions src/equisolve/numpy/_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ def fit(self, X: TensorMap, warm_start: bool = False) -> None:
increasing `n_to_select`. Assumes it is called with the same X.
"""
# Check that we have only 0 or 1 comoponent axes
if len(X.components_names) == 0:
if len(X.component_names) == 0:
has_components = False
elif len(X.components_names) == 1:
elif len(X.component_names) == 1:
has_components = True
else:
assert len(X.components_names) > 1
assert len(X.component_names) > 1
raise ValueError("Can only handle TensorMaps with a single component axis.")

support_blocks = []
Expand Down
4 changes: 2 additions & 2 deletions src/equisolve/numpy/models/linear_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ def fit(
# Create a TensorMap with a single sample and the same components and
# properties as X
samples = Labels(
names=X.samples_names,
values=np.zeros([1, len(X.samples_names)], dtype=int),
names=X.sample_names,
values=np.zeros([1, len(X.sample_names)], dtype=int),
)
new_blocks = []
for X_block in X.blocks():
Expand Down
4 changes: 2 additions & 2 deletions src/equisolve/numpy/preprocessing/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def _validate_data(self, X: TensorMap, y: TensorMap = None):
:param X: training data to check
:param y: target data to check
"""
if len(X.components_names) != 0:
if len(X.component_names) != 0:
raise ValueError("X contains components")

if y is not None:
Expand All @@ -60,7 +60,7 @@ def _validate_data(self, X: TensorMap, y: TensorMap = None):
"Metadata (samples) of X and sample_weight does not agree!"
)

if len(y.components_names) != 0:
if len(y.component_names) != 0:
raise ValueError("y contains components")

def fit(
Expand Down
4 changes: 1 addition & 3 deletions src/equisolve/utils/split_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,7 @@ def _check_args(
if not all([isinstance(name, str) for name in names]):
raise TypeError(f"`names` must be a list of str, got {type(names)}")
for tensor in tensors:
tmp_names = (
tensor.samples_names if axis == "samples" else tensor.properties_names
)
tmp_names = tensor.sample_names if axis == "samples" else tensor.property_names
for name in names:
if name not in tmp_names:
raise ValueError(
Expand Down
4 changes: 2 additions & 2 deletions tests/equisolve_tests/numpy/models/linear_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ def test_alpha_float(self):

# Slice TensorMaps to do not start at sample 0.
# Testing probable hardcoded sample
samples = Labels(names=X.samples_names, values=X[0].samples.values[1:])
samples = Labels(names=X.sample_names, values=X[0].samples.values[1:])
kwargs = {"axis": "samples", "labels": samples}
X = metatensor.slice(X, **kwargs)
y = metatensor.slice(y, **kwargs)
Expand Down Expand Up @@ -604,7 +604,7 @@ def test_components(self):
clf = Ridge()
clf.fit(X=X, y=y)

assert clf.weights.components_names == ["property"]
assert clf.weights.component_names == ["property"]
assert clf.weights[0].values.shape == (1, 1, 1)

@pytest.mark.parametrize(
Expand Down
25 changes: 13 additions & 12 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ envlist =
lint_folders = {toxinidir}/examples {toxinidir}/src {toxinidir}/tests

[testenv]
# we use by default the cpu version of torch, if the cuda version is desired
# please overwrite the PIP_EXTRA_INDEX_URL
setenv =
PIP_EXTRA_INDEX_URL=https://download.pytorch.org/whl/cpu

[testenv:core-numpy-tests]
# this environement runs Python tests with core
description = Runs Python tests with core
usedevelop = true
deps =
ase
Expand All @@ -22,7 +26,7 @@ commands =
pytest --import-mode=append {posargs}

[testenv:core-torch-tests]
# this environement runs Python tests only with metatensor-core
description = Runs Python tests only with metatensor-core
usedevelop = {[testenv:core-numpy-tests]usedevelop}
deps =
{[testenv:core-numpy-tests]deps}
Expand All @@ -31,12 +35,7 @@ commands =
{[testenv:core-numpy-tests]commands}

[testenv:torch-tests]
# this environement runs Python tests with metatensor-torch

# we use by default the cpu version of torch, if the cuda version is desired
# please overwrite the PIP_EXTRA_INDEX_URL
setenv =
PIP_EXTRA_INDEX_URL={env:PIP_EXTRA_INDEX_URL:https://download.pytorch.org/whl/cpu}
description = Runs Python tests with metatensor-torch
usedevelop = {[testenv:core-numpy-tests]usedevelop}
extras = torch
deps =
Expand All @@ -45,6 +44,7 @@ commands =
{[testenv:core-numpy-tests]commands}

[testenv:lint]
description = Run linters
skip_install = true
deps =
flake8
Expand All @@ -57,8 +57,9 @@ commands =
isort --check-only --diff {[tox]lint_folders}

[testenv:format]
# Abuse tox to do actual formatting. Users can call `tox -e format` to run
# formatting on all files
description =
Abuse tox to do actual formatting. Users can call `tox -e format` to run
formatting on all files.
skip_install = true
deps =
black
Expand All @@ -68,7 +69,7 @@ commands =
isort {[tox]lint_folders}

[testenv:docs]
# this environement builds the documentation with sphinx
description = Build the documentation with sphinx
usedevelop = true
setenv =
PIP_EXTRA_INDEX_URL={env:PIP_EXTRA_INDEX_URL:https://download.pytorch.org/whl/cpu}
Expand All @@ -78,7 +79,7 @@ deps =
commands = sphinx-build {posargs:-E} -W -b html docs/src docs/build/html

[testenv:build]
# Make sure we can build sdist and a wheel for python
description = Build sdist and a wheel for python
deps =
build
check-manifest
Expand Down

0 comments on commit 5581630

Please sign in to comment.