Skip to content

Commit

Permalink
make pycddlib optional
Browse files Browse the repository at this point in the history
  • Loading branch information
bobmyhill committed Nov 28, 2024
1 parent 87753d1 commit 730edd3
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions burnman/classes/polytope.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,28 @@
from scipy.spatial import Delaunay
from scipy.special import comb
from copy import copy
import cdd as cdd_float

from .material import cached_property

from ..utils.math import independent_row_indices


# Try to import pycddlib.
# First, try separating the imports into float and
# fractional, then fall back to only using the float
# representation, and finally don't import anything
# (limiting functionality)
try:
cdd_float = importlib.import_module("cdd")
cdd_fraction = importlib.import_module("cdd.gmp")
cdd_gmp_loaded = True
except ImportError:
cdd_fraction = importlib.import_module("cdd")
cdd_gmp_loaded = False
try:
cdd_float = importlib.import_module("cdd")
cdd_fraction = importlib.import_module("cdd")
cdd_gmp_loaded = False
except ImportError:
cdd_float = None


class SimplexGrid(object):
Expand Down Expand Up @@ -140,6 +149,11 @@ def __init__(
dependent endmembers are defined.
:type independent_endmember_occupancies: numpy.array (2D) or None
"""
if cdd_float is None:
raise ImportError(
"You need to install pycddlib to create a MaterialPolytope object."
)

if equalities.dtype != inequalities.dtype:
raise Exception(
f"The equalities and inequalities arrays should have the same type ({equalities.dtype} != {inequalities.dtype})."
Expand Down

0 comments on commit 730edd3

Please sign in to comment.