Skip to content

Commit

Permalink
Finalize Cu-Mg example
Browse files Browse the repository at this point in the history
  • Loading branch information
bocklund committed Aug 13, 2024
1 parent dd1ad3c commit 002af9c
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 71 deletions.
129 changes: 66 additions & 63 deletions tutorials/cu-mg-example/Cu-Mg-mcmc.tdb
Original file line number Diff line number Diff line change
@@ -1,50 +1,51 @@
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$ Date: 2024-08-12 23:56
$ Date: 2021-05-28 17:48
$ Components: CU, MG
$ Phases: CUMG2, FCC_A1, HCP_A3, LAVES_C15, LIQUID
$ Generated by brandonbocklund (pycalphad 0.11.0)
$ Generated by bocklund (pycalphad 0.8.5+13.g5975f7eb.dirty)
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

ELEMENT CU FCC_A1 63.546 5004.1 33.15 !
ELEMENT MG HCP_A3 24.305 4998.0 32.671 !


FUNCTION GFCCCU 298.15 GHSERCU; 3200.0 N !
FUNCTION GFCCMG 298.15 2600.0+GHSERMG-0.9*T; 3000.0 N !
FUNCTION GHCPCU 298.15 600.0+0.2*T+GHSERCU; 3200.0 N !
FUNCTION GHCPMG 298.15 GHSERMG; 3000.0 N !
FUNCTION GHSERCU 298.15 -7770.458-24.112392*T*LOG(T)+130.485235*T
-0.00265684*T**(2)+1.29223E-07*T**(3)+52478.0*T**(-1); 1357.77 Y -13542.026
-31.38*T*LOG(T)+183.803828*T+3.64167E+29*T**(-9); 3200.0 N !
FUNCTION GHSERMG 298.15 -8367.34-26.1849782*T*LOG(T)+143.675547*T
+0.0004858*T**(2)-1.393669E-06*T**(3)+78950.0*T**(-1); 923.0 Y -14130.185
-34.3088*T*LOG(T)+204.716215*T+1.038192E+28*T**(-9); 3000.0 N !
FUNCTION GLIQCU 298.15 12964.735-9.511904*T+GHSERCU-5.8489E-21*T**(7);
1357.77 Y -46.545-31.38*T*LOG(T)+173.881484*T; 3200.0 N !
FUNCTION GLIQMG 298.15 8202.243+GHSERMG-8.83693*T-8.0176E-20*T**(7); 923.0 Y
-5439.869-34.3088*T*LOG(T)+195.324057*T; 3000.0 N !
FUNCTION VV0000 1 13.5733866589811; 10000 N !
FUNCTION VV0001 1 -34605.0604908188; 10000 N !
FUNCTION VV0002 1 -3.90092075977228; 10000 N !
FUNCTION VV0003 1 6317.52716726879; 10000 N !
FUNCTION VV0004 1 4.84087458234797; 10000 N !
FUNCTION VV0005 1 -12020.110557556; 10000 N !
FUNCTION VV0006 1 -25218.7476217562; 10000 N !
FUNCTION VV0007 1 21767.6282490745; 10000 N !
FUNCTION VV0008 1 -20.9561461485966; 10000 N !
FUNCTION VV0009 1 42403.3169242791; 10000 N !
FUNCTION VV0010 1 14.0803059136984; 10000 N !
FUNCTION VV0011 1 -41183.6634669123; 10000 N !
FUNCTION VV0012 1 -26.2686046701225; 10000 N !
FUNCTION VV0013 1 105313.961196921; 10000 N !
FUNCTION VV0014 1 -9.56867641897469; 10000 N !
FUNCTION VV0015 1 25568.2257045211; 10000 N !
FUNCTION VV0016 1 12586.3116298996; 10000 N !
FUNCTION VV0017 1 30973.786970898; 10000 N !
FUNCTION VV0018 1 6.32918274459634; 10000 N !
FUNCTION VV0019 1 -10088.1598777243; 10000 N !
FUNCTION VV0020 1 13.2835488405584; 10000 N !
FUNCTION VV0021 1 -35055.1150347018; 10000 N !
FUNCTION GFCCCU 298.15 GHSERCU#; 3200.0 N !
FUNCTION GFCCMG 298.15 -0.9*T + GHSERMG# + 2600; 3000.0 N !
FUNCTION GHCPCU 298.15 0.2*T + GHSERCU# + 600; 3200.0 N !
FUNCTION GHCPMG 298.15 GHSERMG#; 3000.0 N !
FUNCTION GHSERCU 298.15 1.29223E-7*T**3 - 0.00265684*T**2 - 24.112392*T*LN(T)
+ 130.485235*T - 7770.458 + 52478*T**(-1); 1357.77 Y -31.38*T*LN(T) +
183.803828*T - 13542.026 + 3.64167E+29*T**(-9); 3200.0 N !
FUNCTION GHSERMG 298.15 -1.393669E-6*T**3 + 0.0004858*T**2 -
26.1849782*T*LN(T) + 143.675547*T - 8367.34 + 78950*T**(-1); 923.0 Y
-34.3088*T*LN(T) + 204.716215*T - 14130.185 + 1.038192E+28*T**(-9); 3000.0
N !
FUNCTION GLIQCU 298.15 -5.8489E-21*T**7 - 9.511904*T + GHSERCU# + 12964.735;
1357.77 Y -31.38*T*LN(T) + 173.881484*T - 46.545; 3200.0 N !
FUNCTION GLIQMG 298.15 -8.0176E-20*T**7 - 8.83693*T + GHSERMG# + 8202.243;
923.0 Y -34.3088*T*LN(T) + 195.324057*T - 5439.869; 3000.0 N !
FUNCTION VV0000 1 -32385.6565095649; 10000 N !
FUNCTION VV0001 1 8.89620258484928; 10000 N !
FUNCTION VV0002 1 -3.35091198725963; 10000 N !
FUNCTION VV0003 1 3998.27061812324; 10000 N !
FUNCTION VV0004 1 0.37715194375605; 10000 N !
FUNCTION VV0005 1 -14262.9201608253; 10000 N !
FUNCTION VV0006 1 -23711.7152537579; 10000 N !
FUNCTION VV0007 1 19743.2490274456; 10000 N !
FUNCTION VV0008 1 46921.0878689646; 10000 N !
FUNCTION VV0009 1 -27.8758089555084; 10000 N !
FUNCTION VV0010 1 -38934.8414481184; 10000 N !
FUNCTION VV0011 1 4.48185106717121; 10000 N !
FUNCTION VV0012 1 103588.359410287; 10000 N !
FUNCTION VV0013 1 -36.6096975056103; 10000 N !
FUNCTION VV0014 1 21474.3245402092; 10000 N !
FUNCTION VV0015 1 3.94261220125368; 10000 N !
FUNCTION VV0016 1 8109.35918624189; 10000 N !
FUNCTION VV0017 1 25935.8371792532; 10000 N !
FUNCTION VV0018 1 2.88053789743024; 10000 N !
FUNCTION VV0019 1 -11917.4442504656; 10000 N !
FUNCTION VV0020 1 5.23065525618035; 10000 N !
FUNCTION VV0021 1 -34567.3320157926; 10000 N !

TYPE_DEFINITION % SEQ * !
DEFINE_SYSTEM_DEFAULT ELEMENT 2 !
Expand All @@ -53,54 +54,56 @@ PHASE CUMG2 % 2 1.0 2.0 !
CONSTITUENT CUMG2 :CU:MG: !

PHASE FCC_A1 % 1 1.0 !
CONSTITUENT FCC_A1 :CU, MG: !
CONSTITUENT FCC_A1 :CU,MG: !

PHASE HCP_A3 % 1 1.0 !
CONSTITUENT HCP_A3 :CU, MG: !
CONSTITUENT HCP_A3 :CU,MG: !

PHASE LAVES_C15 % 2 2.0 1.0 !
CONSTITUENT LAVES_C15 :CU, MG:CU, MG: !
CONSTITUENT LAVES_C15 :CU,MG:CU,MG: !

PHASE LIQUID % 1 1.0 !
CONSTITUENT LIQUID :CU, MG: !
CONSTITUENT LIQUID :CU,MG: !



$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$ CU $
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

PARAMETER G(FCC_A1,CU;0) 1.0 GFCCCU; 10000.0 N !
PARAMETER G(HCP_A3,CU;0) 1.0 GHCPCU; 10000.0 N !
PARAMETER G(LAVES_C15,CU:CU;0) 1.0 3.0*GHSERCU+VV0009+T*VV0008; 10000.0 N !
PARAMETER G(LIQUID,CU;0) 1.0 GLIQCU; 10000.0 N !
PARAMETER G(FCC_A1,CU;0) 1.0 GFCCCU#; 10000.0 N !
PARAMETER G(HCP_A3,CU;0) 1.0 GHCPCU#; 10000.0 N !
PARAMETER G(LAVES_C15,CU:CU;0) 1.0 T*VV0009# + 3*GHSERCU# + VV0008#; 10000.0
N !
PARAMETER G(LIQUID,CU;0) 1.0 GLIQCU#; 10000.0 N !


$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$ MG $
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

PARAMETER G(FCC_A1,MG;0) 1.0 GFCCMG; 10000.0 N !
PARAMETER G(HCP_A3,MG;0) 1.0 GHCPMG; 10000.0 N !
PARAMETER G(LAVES_C15,MG:MG;0) 1.0 VV0015+3.0*GHSERMG+T*VV0014; 10000.0 N !
PARAMETER G(LIQUID,MG;0) 1.0 GLIQMG; 10000.0 N !
PARAMETER G(FCC_A1,MG;0) 1.0 GFCCMG#; 10000.0 N !
PARAMETER G(HCP_A3,MG;0) 1.0 GHCPMG#; 10000.0 N !
PARAMETER G(LAVES_C15,MG:MG;0) 1.0 T*VV0015# + 3*GHSERMG# + VV0014#; 10000.0
N !
PARAMETER G(LIQUID,MG;0) 1.0 GLIQMG#; 10000.0 N !


$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$ CU-MG $
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

PARAMETER G(CUMG2,CU:MG;0) 1.0 GHSERCU+T*VV0000+2.0*GHSERMG+VV0001; 10000.0 N
!
PARAMETER L(FCC_A1,CU,MG;0) 1.0 T*VV0004+VV0005; 10000.0 N !
PARAMETER L(FCC_A1,CU,MG;1) 1.0 T*VV0002+VV0003; 10000.0 N !
PARAMETER L(HCP_A3,CU,MG;0) 1.0 VV0007; 10000.0 N !
PARAMETER L(HCP_A3,CU,MG;1) 1.0 VV0006; 10000.0 N !
PARAMETER G(LAVES_C15,CU:MG;0) 1.0 GHSERMG+2.0*GHSERCU+VV0011+T*VV0010;
PARAMETER G(CUMG2,CU:MG;0) 1.0 T*VV0001# + GHSERCU# + 2*GHSERMG# + VV0000#;
10000.0 N !
PARAMETER G(LAVES_C15,MG:CU;0) 1.0 2.0*GHSERMG+GHSERCU+T*VV0012+VV0013;
10000.0 N !
PARAMETER L(LAVES_C15,CU:CU,MG;0) 1.0 VV0016; 10000.0 N !
PARAMETER L(LAVES_C15,CU,MG:MG;0) 1.0 VV0017; 10000.0 N !
PARAMETER L(LIQUID,CU,MG;0) 1.0 T*VV0020+VV0021; 10000.0 N !
PARAMETER L(LIQUID,CU,MG;1) 1.0 T*VV0018+VV0019; 10000.0 N !
PARAMETER L(FCC_A1,CU,MG;0) 1.0 T*VV0004# + VV0005#; 10000.0 N !
PARAMETER L(FCC_A1,CU,MG;1) 1.0 T*VV0002# + VV0003#; 10000.0 N !
PARAMETER L(HCP_A3,CU,MG;0) 1.0 VV0007#; 10000.0 N !
PARAMETER L(HCP_A3,CU,MG;1) 1.0 VV0006#; 10000.0 N !
PARAMETER G(LAVES_C15,CU:MG;0) 1.0 T*VV0011# + 2*GHSERCU# + GHSERMG# +
VV0010#; 10000.0 N !
PARAMETER G(LAVES_C15,MG:CU;0) 1.0 T*VV0013# + GHSERCU# + 2*GHSERMG# +
VV0012#; 10000.0 N !
PARAMETER L(LAVES_C15,CU:CU,MG;0) 1.0 VV0016#; 10000.0 N !
PARAMETER L(LAVES_C15,CU,MG:MG;0) 1.0 VV0017#; 10000.0 N !
PARAMETER L(LIQUID,CU,MG;0) 1.0 T*VV0020# + VV0021#; 10000.0 N !
PARAMETER L(LIQUID,CU,MG;1) 1.0 T*VV0018# + VV0019#; 10000.0 N !
19 changes: 16 additions & 3 deletions tutorials/cu-mg-example/cu-mg-example.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,29 @@ as autocorrelation. Qualitatively, this run does not appear converged
after 115 iterations.

``` {python}
iterations = np.arange(1, trace.shape[1]+1)
fig, ax = plt.subplots()
ax.plot(lnprob.T)
ax.plot(iterations, lnprob.T)
ax.set_title("log-probability convergence")
ax.set_xlabel("iterations")
ax.set_ylabel("lnprob")
ax.set_yscale("symlog") # log-probabilties are often negative, symlog gives log scale for negative numbers
fig.show()
```

Next we'll discard a number of iterations to account for the MCMC optimizer reaching the typical set.
```{python}
burn_in_iterations = 1000
fig, ax = plt.subplots()
ax.plot(iterations[burn_in_iterations:], lnprob[:,burn_in_iterations:].T)
ax.set_title("log-probability convergence")
ax.set_xlabel("iterations")
ax.set_ylabel("lnprob")
fig.show()
```

After discarding the first `{python} burn_in_iterations` iterations as burn-in, we can see the chains are mixing well and exploring near the mode of the distribution.

### Visualizing the trace of each parameter

We would like to see how each parameter changed during the iterations.
Expand Down Expand Up @@ -274,9 +288,8 @@ because increasing one parameter while decreasing another would give a
similar error.

``` {python}
#| warning: false
#| warning: false
import corner
burn_in_iterations = 50
fig = plt.figure(figsize=(16,16)) # this is a little condensed for the web view
# flatten the along the first dimension containing all the chains in parallel
corner.corner(trace[:, burn_in_iterations:, :].reshape(-1, trace.shape[-1]), fig=fig)
Expand Down
4 changes: 2 additions & 2 deletions tutorials/cu-mg-example/lnprob.npy
Git LFS file not shown
3 changes: 2 additions & 1 deletion tutorials/cu-mg-example/run_mcmc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ output:
probfile: lnprob.npy
logfile: mcmc-log.txt
mcmc:
iterations: 1000
iterations: 2000
save_interval: 1
scheduler: null # don't parallelize, just run on one core
input_db: Cu-Mg-generated.tdb
chains_per_parameter: 4
prior:
name: normal
loc_relative: 1.0
Expand Down
4 changes: 2 additions & 2 deletions tutorials/cu-mg-example/trace.npy
Git LFS file not shown

0 comments on commit 002af9c

Please sign in to comment.