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

ENH: CompositionSet-based solver API #415

Merged
merged 25 commits into from
May 19, 2022

Conversation

richardotis
Copy link
Collaborator

  • Created new SystemState and SystemSpecification objects. SystemSpecification captures the desired result of a particular calculation and associated convergence criteria, while SystemState represents the state of a calculation. The pre-existing Solver object now uses a SystemSpecification to evolve a SystemState object until it achieves the convergence criteria in the specification (this is the specification's run_loop method). SystemSpecification provides a convenience method, get_new_state, which allows users to pass in a list of CompositionSet objects and get back a SystemState.
  • Removed update_composition_sets and solve_and_update in eqsolver

Solver.solve can still be used as normal, but because the solver internals have been modularized, users have more control over the minimization process now. For example, solves can now be performed with a list CompositionSet objects as both input and output (mutated in place).

# composition_sets is a list of CompositionSet representing a starting point
# conditions is a dict mapping state variable strings to floats
solver = Solver(remove_metastable=False) # will not delete CompositionSets found to be metastable
spec = solver.get_system_spec(composition_sets, conditions)
state = spec.get_new_state(composition_sets)
converged = spec.run_loop(state, 1000)
# composition_sets has been mutated with the result (solution meets convergence criteria if converged is True)

This is also useful for toggling the fixed state of a list of CompositionSet objects in place, which makes it convenient to do sequences of minimization operations with varying conditions.

@richardotis richardotis added this to the 0.10.1 milestone May 17, 2022
@richardotis richardotis changed the title ENH: Improvements to solver API ENH: CompositionSet-based solver API May 17, 2022
@codecov
Copy link

codecov bot commented May 17, 2022

Codecov Report

Merging #415 (4d3910d) into develop (f8e3951) will decrease coverage by 0.44%.
The diff coverage is 88.00%.

@@             Coverage Diff             @@
##           develop     #415      +/-   ##
===========================================
- Coverage    90.67%   90.22%   -0.45%     
===========================================
  Files           45       50       +5     
  Lines         6335     7696    +1361     
===========================================
+ Hits          5744     6944    +1200     
- Misses         591      752     +161     
Impacted Files Coverage Δ
pycalphad/core/minimizer.pyx 83.47% <84.04%> (ø)
pycalphad/core/eqsolver.pyx 85.00% <100.00%> (ø)
pycalphad/core/solver.py 100.00% <100.00%> (ø)
pycalphad/codegen/sympydiff_utils.py 98.21% <0.00%> (-1.79%) ⬇️
pycalphad/tests/test_utils.py 100.00% <0.00%> (ø)
pycalphad/models/model_mqmqa.py 88.42% <0.00%> (ø)
pycalphad/tests/test_database.py 100.00% <0.00%> (ø)
pycalphad/tests/test_calculate.py 100.00% <0.00%> (ø)
pycalphad/core/hyperplane.pyx 93.67% <0.00%> (ø)
... and 9 more

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

pycalphad/core/minimizer.pyx Outdated Show resolved Hide resolved
pycalphad/core/minimizer.pyx Outdated Show resolved Hide resolved
@bocklund
Copy link
Collaborator

Thanks for getting coverage working. Looks like Cython code isn't far from the rest of the repo in coverage. For the minimizer, it looks like a fixed compset + free state variable would cover many of the missed lines (not a blocker for this PR, IMO).

@bocklund
Copy link
Collaborator

bocklund commented May 19, 2022

@richardotis is this ready for re-review now?

@richardotis
Copy link
Collaborator Author

richardotis commented May 19, 2022

@bocklund It's ready as of 4d3910d. I made a small refactor to solve_state which doesn't do much here, but it makes it easier to implement dot derivatives for some uncommitted local changes which are allowing me to compute the key differential quantity in Equation 78 of Sundman et al, 2015. I thought it made sense to get it in now as part of this review.

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

Successfully merging this pull request may close these issues.

2 participants