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

formatted_parameter broken by SymEngine #238

Open
bocklund opened this issue Jul 11, 2022 · 0 comments
Open

formatted_parameter broken by SymEngine #238

bocklund opened this issue Jul 11, 2022 · 0 comments

Comments

@bocklund
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant