Skip to content

formatted_parameter broken by SymEngine #238

@bocklund

Description

@bocklund

Switching the symbolic backend to SymEngine broke espei.utils.formatted_parameter. Here's a test to validate (run from the tests directory for the testing_data module to be importable).

# espei/tests/test_utils.py

from pycalphad import Database
from espei.utils import formatted_parameter, database_symbols_to_fit
from .testing_data import CU_MG_TDB
def test_cu_mg_parameters_can_be_formatted_to_strings():
    """Formating parameters should work for common variables parameters"""
    dbf = Database(CU_MG_TDB)
    for sym in database_symbols_to_fit(dbf):
        assert isinstance(formatted_parameter(dbf, sym), str), f"Formatted parameter for symbol {sym} (value = {dbf.symbols[sym]}) in database not a string"

Running this gives an error:

Traceback (most recent call last):
  File "/Users/bocklund1/src/calphad/espei/tests/dummy.py", line 11, in <module>
    test_cu_mg_parameters_can_be_formatted_to_strings()
  File "/Users/bocklund1/src/calphad/espei/tests/dummy.py", line 9, in test_cu_mg_parameters_can_be_formatted_to_strings
    assert isinstance(formatted_parameter(dbf, sym), str), f"Formatted parameter for symbol {sym} (value = {dbf.symbols[sym]}) in database not a string"
  File "/Users/bocklund1/src/calphad/espei/espei/utils.py", line 295, in formatted_parameter
    term = parameter_term(result['parameter'], symbol)
  File "/Users/bocklund1/src/calphad/espei/espei/utils.py", line 218, in parameter_term
    coeff, root = term_coeff.as_coeff_mul(symbol)
AttributeError: 'symengine.lib.symengine_wrapper.Symbol' object has no attribute 'as_coeff_mul'

I think the breakage might be because espei.utils.parameter_term isn't correctly picking up the first condition, since for the case of symbol being a symengine.lib.symengine_wrapper.Symbol, I think expression == symbol should evaluate to true, but evidently (via the traceback) it is evaluating to false.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions