From b29b7ca66dbb6d0db964c11d27c51e05a000c0e2 Mon Sep 17 00:00:00 2001 From: Bob Myhill Date: Mon, 7 Oct 2024 18:11:24 +0100 Subject: [PATCH] test different pycddlib versions --- burnman/classes/polytope.py | 1 - test.sh | 4 ++++ tests/test_polytope.py | 47 ++++++++++++++++++++++++++++++++++++- 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/burnman/classes/polytope.py b/burnman/classes/polytope.py index b59ddf98..c0dcf393 100644 --- a/burnman/classes/polytope.py +++ b/burnman/classes/polytope.py @@ -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 diff --git a/test.sh b/test.sh index ccd58416..17ae0146 100755 --- a/test.sh +++ b/test.sh @@ -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 diff --git a/tests/test_polytope.py b/tests/test_polytope.py index d6b89d50..e1500570 100644 --- a/tests/test_polytope.py +++ b/tests/test_polytope.py @@ -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): @@ -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()