Skip to content

Commit

Permalink
test different pycddlib versions
Browse files Browse the repository at this point in the history
  • Loading branch information
bobmyhill committed Oct 7, 2024
1 parent 1484af3 commit b29b7ca
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
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()

0 comments on commit b29b7ca

Please sign in to comment.