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
ENH: Workspace API #432
base: develop
Are you sure you want to change the base?
ENH: Workspace API #432
Conversation
…r of a dot derivative
…a separate module
…es on some platforms
… is specified that causes the phase to have zero feasible points. Fixes pycalphadgh-503
I'm just starting to use this a bit, I'm wondering if I missed if there's a hook to give units for |
The way it works at the moment is somewhat hacky. You can assign a variable to this module: https://github.com/richardotis/pycalphad/blob/a0541fe69317348d0627ab72440b00c84a3891a0/pycalphad/property_framework/units.py#L22-L36 |
…, for pickling support
… conditions in multi-component systems
I came across a bug for ternaries when using the cpf for mole fractions specified to be greater than one. Here's some code to reproduce: @select_database("alnipt.tdb")
def test_jansson_derivative_with_invalid_mass_conditions(load_database):
"""
CPF values including Jansson derivatives computed for conditions that are invalid should produce NaN.
"""
# change to load_database() for the actual test
dbf = load_database()
wks = Workspace(dbf, ["AL", "NI", "PT"], ["LIQUID"], {v.T: 298.15, v.P: 101325, v.N: 1, v.X("AL"): 0.6, v.X("PT"): 0.6})
T = wks.get("T")
assert np.isnan(T)
GM = wks.get("GM")
assert np.isnan(GM)
dGM_dT = wks.get("GM.T")
assert np.isnan(dGM_dT) # The following code can be used to test interactively
import numpy as np
from pycalphad import variables as v
from pycalphad.core.workspace import Workspace
from pycalphad import Database
from importlib_resources import files
import pycalphad.tests.databases
dbf = Database(str(files(pycalphad.tests.databases).joinpath("alnipt.tdb")))
wks = Workspace(dbf, ["AL", "NI", "PT"], ["LIQUID"], {v.T: 298.15, v.P: 101325, v.N: 1, v.X("AL"): 0.6, v.X("PT"): 0.6})
T = wks.get("T") # currently NaN
print(T)
GM = wks.get("GM") # currently 0
print(GM)
dGM_dT = wks.get("GM.T") # raises exception
print(dGM_dT) ---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
Cell In[23], line 30
28 GM = wks.get("GM") # currently 0
29 print(GM)
---> 30 dGM_dT = wks.get("GM.T") # raises exception
31 print(dGM_dT)
File ~/src/pycalphad-workspace-development/pycalphad/pycalphad/core/workspace.py:425, in Workspace.get(self, values_only, *args)
423 if results.get(arg, None) is None:
424 results[arg] = np.zeros((arr_size,) + arg.shape)
--> 425 results[arg][local_index, ...] = Q_(arg.compute_property(composition_sets, cur_conds, chemical_potentials),
426 prop_implementation_units).to(prop_display_units, context).magnitude
427 local_index += 1
429 for arg in args:
File ~/src/pycalphad-workspace-development/pycalphad/pycalphad/property_framework/computed_property.py:288, in DotDerivativeComputedProperty.compute_property(self, compsets, cur_conds, chemical_potentials)
286 solver = Solver()
287 print(compsets)
--> 288 spec = solver.get_system_spec(compsets, cur_conds)
289 state = spec.get_new_state(compsets)
290 state.chemical_potentials[:] = chemical_potentials
File ~/src/pycalphad-workspace-development/pycalphad/pycalphad/core/solver.py:54, in Solver.get_system_spec(self, composition_sets, conditions)
52 from pycalphad.variables import ChemicalPotential, MoleFraction, SiteFraction
53 compsets = composition_sets
---> 54 state_variables = compsets[0].phase_record.state_variables
55 nonvacant_elements = compsets[0].phase_record.nonvacant_elements
56 num_statevars = len(state_variables)
IndexError: list index out of range It doesn't currently seem to affect binaries, i.e. X_AL = 2.0
wks = Workspace(dbf, ["AL", "NI"], ["LIQUID"], {v.T: 298.15, v.P: 101325, v.N: 1, v.X("AL"): X_AL}) seems to work for any value of It also breaks for tuple conditions as if they were passed as scalars, for example
works for the first 2 conditions |
The test assumes that the value of |
Workspace
object and associated imperative API. This object now underlies theequilibrium
function, which remains for backwards compatibility. AWorkspace
object can be mutated after creation. TheWorkspace.get()
function acceptsComputableProperty
objects as input and returns arrays; theWorkspace.plot()
function works similarly, but returns amatplotlib
figure. Fixes Develop a wrapper API for plotting properties from calculate and equilibrium #154PhaseRecordFactory
object and associated connections toPhaseRecord
, which enables deferred compilation of symbolically-defined model properties until they are called in thePhaseRecord
API. ThePhaseRecord
object also gainsprop
andprop_grad
functions for computing properties and property gradients of arbitrary symbolic attributes ofModel
instances.IsolatedPhase
andDormantPhase
meta-properties. Meta-properties are objects that know how to create new properties (as defined by the CPF). In this case, these meta-properties know how to start sub-calculations . The current way of finding starting points for these calculations is not ideal and prone to failure (basically reusesCompositionSet
objects from the workspace equilibrium calculation), but it works well in the typical case.pint
. AllComputableProperty
objects have "implementation units" and "display units." Implementation units are what are assumed by the underlying numerical computation (which is done without units, for performance). The display units are what the user gets whenWorkspace.get
orWorkspace.plot
are called.ComputableProperty.__getitem__
allows the display units to be changed for individual calls toWorkspace.get
,Workspace.plot
, or when settingWorkspace.conditions
.Documentation
PandasRenderer
.setup.py
(runtime requirements)