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

add test suite for full pycddlib to GitHub actions #602

Merged
merged 2 commits into from
Oct 7, 2024
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
29 changes: 29 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,32 @@ jobs:
- name: test
run: |
PYTHON=python ./test.sh

linux_full_pycddlib:
name: test with full pycddlib
runs-on: [ubuntu-24.04]

strategy:
matrix:
python-versions: ['3.9', '3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-versions }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-versions }}
- name: setup
run: |
sudo apt update && sudo apt install --yes \
libcdd-dev \
libgmp-dev \
numdiff \
texlive \
texlive-latex-extra
python -m pip install --upgrade pip
pip install pycddlib autograd # this is optional
python --version
- name: test with full pycddlib
run: |
PYTHON=python ./test.sh
1 change: 0 additions & 1 deletion burnman/classes/polytope.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import importlib
import numpy as np
from sympy import Rational
from fractions import Fraction
from scipy.spatial import Delaunay
from scipy.special import comb
Expand Down
4 changes: 4 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ echo ""
echo "Dependency tree:"
$PYTHON -m pip install -q pipdeptree .
$PYTHON -m pipdeptree -p burnman -d 1 2> /dev/null
pycddlib_version=`pip freeze | grep "pycddlib=" | awk -F"==" '{print $2}'`
if [ ! -z "${pycddlib_version}" ]
then echo "└── pycddlib [optional, installed: ${pycddlib_version}]"
fi
echo ""

# Quietly install optional modules after burnman
Expand Down
47 changes: 46 additions & 1 deletion tests/test_polytope.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
import unittest
from util import BurnManTest
import numpy as np
from sympy import Matrix
from fractions import Fraction
import importlib

from burnman import Composite
from burnman.minerals import SLB_2011
from burnman.minerals import SLB_2011, JH_2015
from burnman.tools.polytope import solution_polytope_from_charge_balance
from burnman.tools.polytope import solution_polytope_from_endmember_occupancies
from burnman.tools.polytope import simplify_composite_with_composition
from burnman import MaterialPolytope


class polytope(BurnManTest):
Expand Down Expand Up @@ -62,6 +66,47 @@ def test_simplify_composite_and_composition(self):
self.assertEqual(strings[1], "[Mg]3[Mg][Si]")
self.assertArraysAlmostEqual([0.1, 0.9], new_gt.molar_fractions)

def test_cddlib_versions(self):
gt = JH_2015.garnet()
endmember_occupancies = gt.solution_model.endmember_occupancies

n_sites = sum(endmember_occupancies[0])
n_occs = endmember_occupancies.shape[1]

nullspace = np.array(Matrix(endmember_occupancies).nullspace(), dtype=float)

equalities = np.zeros((len(nullspace) + 1, n_occs + 1))
equalities[0, 0] = -n_sites
equalities[0, 1:] = 1
if len(nullspace) > 0:
try:
equalities[1:, 1:] = nullspace
except ValueError:
equalities[1:, 1:] = nullspace[:, :, 0]

pos_constraints = np.concatenate(
(
np.zeros((len(equalities[0]) - 1, 1)),
np.identity(len(equalities[0]) - 1),
),
axis=1,
)

equalities = np.array([[Fraction(v) for v in r] for r in equalities])
pos_constraints = np.array([[Fraction(v) for v in r] for r in pos_constraints])

poly = MaterialPolytope(
equalities,
pos_constraints,
independent_endmember_occupancies=endmember_occupancies,
)

try:
_ = importlib.import_module("cdd.gmp")
self.assertTrue(type(poly.raw_vertices[0][0]) is Fraction)
except ImportError:
self.assertTrue(type(poly.raw_vertices[0][0]) is float)


if __name__ == "__main__":
unittest.main()
Loading