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

FIX: Dataset exclusion query for duplicated excluded model contributions #263

Merged
merged 2 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def get_thermochemical_data(dbf, comps, phases, datasets, model=None, weight_dic
if exclusion == tuple([]):
exc_search = (~where('excluded_model_contributions').exists()) & (where('solver').exists())
else:
exc_search = (where('excluded_model_contributions').test(lambda x: tuple(sorted(x)) == exclusion)) & (where('solver').exists())
exc_search = (where('excluded_model_contributions').test(lambda x: tuple(sorted(set(x))) == exclusion)) & (where('solver').exists())
curr_data = get_prop_data(comps, phase_name, prop, datasets, additional_query=exc_search)
curr_data = filter_sublattice_configurations(curr_data, constituents)
curr_data = filter_temperatures(curr_data)
Expand Down
15 changes: 15 additions & 0 deletions tests/test_error_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,21 @@ def test_fixed_configuration_residual_function(datasets_db):
assert np.isclose(likelihood, -14.28729, rtol=1e-6)


def test_fixed_configuration_residual_function_duplicate_excluded_model_contributions(datasets_db):
"""Datasets where a excluded model contribution is duplicated is in the excluded model contributions contributes to the residual"""
dbf = Database(CU_MG_TDB)
datasets_db.insert(CU_MG_HM_MIX_CUMG2_ANTISITE_DUPLICATE_EXCLUDED_MODEL_CONTRIBUTIONS)

residual_func = FixedConfigurationPropertyResidual(dbf, datasets_db, phase_models=None, symbols_to_fit=[])

# Regression test "truth" values - got values by running
residuals, weights = residual_func.get_residuals(np.asarray([]))
assert len(residuals) == len(weights)
assert np.allclose(residuals, [-10.0, -100.0])
likelihood = residual_func.get_likelihood(np.asarray([]))
assert np.isclose(likelihood, -14.28729, rtol=1e-6)


def test_fixed_configuration_residual_with_internal_degrees_of_freedom(datasets_db):
"""Unstable endmembers in phases that have internal degrees of freedom should retain fixed internal DOF"""
dbf = Database(CU_MG_TDB)
Expand Down
22 changes: 22 additions & 0 deletions tests/testing_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,28 @@
""", Loader=YAML_LOADER)


CU_MG_HM_MIX_CUMG2_ANTISITE_DUPLICATE_EXCLUDED_MODEL_CONTRIBUTIONS = yaml.load("""{
"components": ["CU", "MG", "VA"],
"phases": ["CUMG2"],
"solver": {
"sublattice_site_ratios": [1, 2],
"sublattice_configurations": [["CU", "MG"], ["MG", "CU"], ["MG", "MG"], ["CU", "CU"]],
"mode": "manual"
},
"conditions": {
"P": 101325,
"T": [300, 400],
},

"output": "HM_MIX",
"values": [[[10, 11, 12, 13], [100, 101, 102, 103]]],
"reference": "FAKE DATA",
"comment": "FAKE DATA",
"excluded_model_contributions": ["idmix", "idmix"]
}
""", Loader=YAML_LOADER)


CU_MG_HM_MIX_CUMG2_ALL_INVALID = yaml.load("""{
"components": ["CU", "MG", "VA"],
"phases": ["CUMG2"],
Expand Down
Loading