Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve test coverage #83

Merged
merged 10 commits into from
Jun 9, 2023
Merged
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
4 changes: 4 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[run]
branch = True
source = pymuonsuite
omit = pymuonsuite/test/*
7 changes: 5 additions & 2 deletions .github/workflows/python-package-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ jobs:
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
shell: bash # Windows runners have Git Bash installed so this should work on all runners
- name: Install package
run: pip install .
run: pip install -e .
- name: Test with pytest
run: pytest
run: pytest --cov pymuonsuite --cov-report xml
- name: Upload to Codecov
if: matrix.python-version == '3.10' && matrix.os == 'ubuntu-latest'
uses: codecov/codecov-action@v3
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ htmlcov/
.cache
nosetests.xml
coverage.xml
coverage
*.cover
.hypothesis/
.pytest_cache/
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[![Build Status](https://github.com/muon-spectroscopy-computational-project/pymuon-suite/actions/workflows/python-package-tests.yml/badge.svg?branch=main)](https://github.com/muon-spectroscopy-computational-project/pymuon-suite/actions/workflows/python-package-tests.yml)
[![Codecov](https://codecov.io/gh/muon-spectroscopy-computational-project/pymuon-suite/branch/main/graph/badge.svg)](https://codecov.io/gh/muon-spectroscopy-computational-project/pymuon-suite)

# pymuon-suite
Collection of scripts and utilities for muon spectroscopy.

Expand Down
8 changes: 4 additions & 4 deletions pymuonsuite/calculate/hfine.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ def compute_hfine_tensor(
N = len(points)

magmoms = np.array(spins).astype(float)
species = np.array(species).astype("S2")
species = np.array(species)
if species.shape == ():
species = np.repeat(species[None], N)
for i, s in enumerate(species):
if s == b"e":
if s == "e":
mm = 2 * _bohrmag
elif s == b"mu":
elif s == "mu":
mm = mu_cnst.m_gamma * cnst.hbar
else:
mm = _get_isotope_data(s, "gamma")[0] * cnst.hbar
Expand Down Expand Up @@ -140,7 +140,7 @@ def compute_hfine_mullpop(
| magnetization). Default is True
| fermi (bool): if True, include a Fermi contact term
| (magnetization at site i). Default is True
| fermi_neigh (bool): if True, include an empyrical neighbour
| fermi_neigh (bool): if True, include an empirical neighbour
| correction for the Fermi contact term.
| Default is False

Expand Down
33 changes: 17 additions & 16 deletions pymuonsuite/calculate/uep/charged.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,18 @@ def has_spin(self):
def thomasFermiE(self):
return self._thomasFermiE

def _validate_points(self, points: object) -> np.ndarray:
"""Ensure that points has at least two dimensions.

Arguments:
points {object} -- List of points to be validated.

Returns:
np.ndarray -- Array of points with at least two dimensions
"""
points = np.array(points)
return points[None, :] if len(points.shape) == 1 else points

def rho(self, p, max_process_p=20):
"""Charge density

Expand All @@ -262,9 +274,7 @@ def rho(self, p, max_process_p=20):
"""

# Return charge density at a point or list of points
p = np.array(p)
if len(p.shape) == 1:
p = p[None, :] # Make it into a list of points
p = self._validate_points(p)

# The point list is sliced for convenience, to avoid taking too much
# memory
Expand Down Expand Up @@ -308,9 +318,7 @@ def V(self, p, max_process_p=20):
"""

# Return potential at a point or list of points
p = np.array(p)
if len(p.shape) == 1:
p = p[None, :] # Make it into a list of points
p = self._validate_points(p)

# The point list is sliced for convenience, to avoid taking too much
# memory
Expand Down Expand Up @@ -356,9 +364,7 @@ def dV(self, p, max_process_p=20):
"""

# Return potential gradient at a point or list of points
p = np.array(p)
if len(p.shape) == 1:
p = p[None, :] # Make it into a list of points
p = self._validate_points(p)

# The point list is sliced for convenience, to avoid taking too much
# memory
Expand Down Expand Up @@ -409,10 +415,7 @@ def d2V(self, p, max_process_p=20):
"""

# Return potential Hessian at a point or a list of points

p = np.array(p)
if len(p.shape) == 1:
p = p[None, :] # Make it into a list of points
p = self._validate_points(p)

# The point list is sliced for convenience, to avoid taking too much
# memory
Expand Down Expand Up @@ -481,9 +484,7 @@ def Hfine(self, p, contact=False, max_process_p=20):
)

# Return hyperfine tensors at a point or a list of points
p = np.array(p)
if len(p.shape) == 1:
p = p[None, :] # Make it into a list of points
p = self._validate_points(p)

# The point list is sliced for convenience, to avoid taking too much
# memory
Expand Down
21 changes: 0 additions & 21 deletions pymuonsuite/io/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,6 @@
from soprano.utils import silence_stdio


def write_tensors(tensors, filename, symbols):
"""
Write out a set of 2 dimensional tensors for every atom in a system.

| Args:
| tensors(Numpy float array, shape: (Atoms, :, :): A list of tensors
| for each atom.
| filename(str): Filename for file.
| symbols(str array): List containing chemical symbol of each atom in
| system.
|
| Returns: Nothing
"""
tensfile = open(filename, "w")
for i in range(np.size(tensors, 0)):
tensfile.write("{0} {1}\n".format(symbols[i], i))
tensfile.write(
"\n".join(["\t".join([str(x) for x in ln]) for ln in tensors[i]]) + "\n"
)


def write_cluster_report(args, params, clusters):

if params["clustering_method"] == "hier":
Expand Down
6 changes: 2 additions & 4 deletions pymuonsuite/muairss.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,12 @@ def muairss_batch_io(args, global_params, save=False):

for path in structure_files:
name = parse_structure_name(path)
parameter_file = os.path.join(structures_path, "{}.yaml".format(name))
if not os.path.isfile(parameter_file):
parameter_file = None
with silence_stdio():
struct = io.read(path)
params = dict(global_params) # Copy
params["name"] = name
if parameter_file is not None:
parameter_file = os.path.join(structures_path, "{}.yaml".format(name))
if os.path.isfile(parameter_file):
params = load_input_file(parameter_file, MuAirssSchema, merge=params)
params["out_folder"] = params["name"]

Expand Down
177 changes: 0 additions & 177 deletions pymuonsuite/quantum/vibrational/grid.py

This file was deleted.

Loading