Skip to content

Commit

Permalink
MAINT: PyCalphad Workspace compatibility (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
nury12n authored Jul 19, 2024
1 parent 05a89a9 commit ff82d79
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
fail-fast: false
max-parallel: 100
matrix:
python-version: [3.7, 3.8, 3.9]
python-version: ["3.9", "3.10", "3.11", "3.12"]
pycalphad_develop_version: [true, false]

steps:
Expand Down
30 changes: 19 additions & 11 deletions scheil/simulate.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys
import numpy as np
from pycalphad import equilibrium, variables as v
from pycalphad.codegen.callables import build_phase_records
from pycalphad.codegen.phase_record_factory import PhaseRecordFactory
from pycalphad.core.calculate import _sample_phase_constitution
from pycalphad.core.utils import instantiate_models, unpack_components, filter_phases, point_sample
from .solidification_result import SolidificationResult
Expand Down Expand Up @@ -97,10 +97,12 @@ def simulate_scheil_solidification(dbf, comps, phases, composition,
T_STEP_ORIG = step_temperature
phases = filter_phases(dbf, unpack_components(dbf, comps), phases)
ordering_records = create_ordering_records(dbf, comps, phases)
models = instantiate_models(dbf, comps, phases)
if 'model' not in eq_kwargs:
eq_kwargs['model'] = instantiate_models(dbf, comps, phases)
eq_kwargs['phase_records'] = PhaseRecordFactory(dbf, comps, [v.N, v.P, v.T], eq_kwargs['model'])
models = eq_kwargs['model']
if verbose:
print('building PhaseRecord objects... ', end='')
phase_records = build_phase_records(dbf, comps, phases, [v.N, v.P, v.T], models)
if verbose:
print('done')
filtered_disordered_phases = {ord_rec.disordered_phase_name for ord_rec in ordering_records}
Expand All @@ -124,7 +126,9 @@ def simulate_scheil_solidification(dbf, comps, phases, composition,
if verbose:
print(phase_name, end=' ')
pdens = eq_kwargs['calc_opts'].get('pdens', 50)
points_dict[phase_name] = _sample_phase_constitution(mod, point_sample, True, pdens=pdens)
# Assume no phase_local_conditions, this is probably okay since there's no option to add additional conditions here
# And I don't think it would make too much sense to have phase local conditions for scheil/eq solidification anyways
points_dict[phase_name] = _sample_phase_constitution(mod, point_sample, True, pdens=pdens, phase_local_conditions={})
eq_kwargs['calc_opts']['points'] = points_dict
if verbose:
print('done')
Expand All @@ -137,7 +141,7 @@ def simulate_scheil_solidification(dbf, comps, phases, composition,
comp_conds = liquid_comp
fmt_comp_conds = ', '.join([f'{c}={val:0.2f}' for c, val in comp_conds.items()])
conds.update(comp_conds)
eq = equilibrium(dbf, comps, phases, conds, model=models, phase_records=phase_records, to_xarray=False, **eq_kwargs)
eq = equilibrium(dbf, comps, phases, conds, to_xarray=False, **eq_kwargs)
if adaptive:
_update_points(eq, eq_kwargs['calc_opts']['points'], dof_dict, verbose=verbose)
eq = eq.get_dataset() # convert LightDataset to Dataset for fancy indexing
Expand Down Expand Up @@ -264,10 +268,12 @@ def simulate_equilibrium_solidification(dbf, comps, phases, composition,
filtered_disordered_phases = {ord_rec.disordered_phase_name for ord_rec in ordering_records}
solid_phases = sorted((set(phases) | filtered_disordered_phases) - {liquid_phase_name})
independent_comps = sorted([str(comp)[2:] for comp in composition.keys()])
models = instantiate_models(dbf, comps, phases)
if 'model' not in eq_kwargs:
eq_kwargs['model'] = instantiate_models(dbf, comps, phases)
eq_kwargs['phase_records'] = PhaseRecordFactory(dbf, comps, [v.N, v.P, v.T], eq_kwargs['model'])
models = eq_kwargs['model']
if verbose:
print('building PhaseRecord objects... ', end='')
phase_records = build_phase_records(dbf, comps, phases, [v.N, v.P, v.T], models)
if verbose:
print('done')
conds = {v.P: 101325, v.N: 1.0}
Expand All @@ -283,7 +289,9 @@ def simulate_equilibrium_solidification(dbf, comps, phases, composition,
points_dict = {}
for phase_name, mod in models.items():
pdens = eq_kwargs['calc_opts'].get('pdens', 50)
points_dict[phase_name] = _sample_phase_constitution(mod, point_sample, True, pdens=pdens)
# Assume no phase_local_conditions, this is probably okay since there's no option to add additional conditions here
# And I don't think it would make too much sense to have phase local conditions for scheil/eq solidification anyways
points_dict[phase_name] = _sample_phase_constitution(mod, point_sample, True, pdens=pdens, phase_local_conditions = {})
eq_kwargs['calc_opts']['points'] = points_dict

temperatures = []
Expand All @@ -300,7 +308,7 @@ def simulate_equilibrium_solidification(dbf, comps, phases, composition,
conds[v.T] = current_T
if verbose:
print(f'{current_T} ', end='')
eq = equilibrium(dbf, comps, phases, conds, model=models, phase_records=phase_records, to_xarray=False, **eq_kwargs)
eq = equilibrium(dbf, comps, phases, conds, to_xarray=False, **eq_kwargs)
if not is_converged(eq):
if verbose:
comp_conds = {cond: val for cond, val in conds.items() if isinstance(cond, v.X)}
Expand All @@ -326,7 +334,7 @@ def simulate_equilibrium_solidification(dbf, comps, phases, composition,
while (T_high - T_low) > binary_search_tol:
bin_search_T = (T_high - T_low) * 0.5 + T_low
conds[v.T] = bin_search_T
eq = equilibrium(dbf, comps, phases, conds, model=models, phase_records=phase_records, to_xarray=False, **eq_kwargs)
eq = equilibrium(dbf, comps, phases, conds, to_xarray=False, **eq_kwargs)
if adaptive:
# Update the points dictionary with local samples around the equilibrium site fractions
_update_points(eq, eq_kwargs['calc_opts']['points'], dof_dict)
Expand All @@ -341,7 +349,7 @@ def simulate_equilibrium_solidification(dbf, comps, phases, composition,
converged = True
conds[v.T] = T_low
temperatures.append(T_low)
eq = equilibrium(dbf, comps, phases, conds, model=models, phase_records=phase_records, to_xarray=False, **eq_kwargs)
eq = equilibrium(dbf, comps, phases, conds, to_xarray=False, **eq_kwargs)
if not is_converged(eq):
if verbose:
comp_conds = {cond: val for cond, val in conds.items() if isinstance(cond, v.X)}
Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ def readme(fname):
'License :: OSI Approved :: MIT License',

'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
],
)

0 comments on commit ff82d79

Please sign in to comment.