Skip to content
Snippets Groups Projects

Draft: New dockerfile

Open Adam Fekete requested to merge refactor into master
1 unresolved thread
1 file
+ 57
43
Compare changes
  • Side-by-side
  • Inline
``` python
``` python
 
import contextlib
 
import numpy as np
import os
import os
import pandas as pd
import pandas as pd
import numpy as np
import shutil
 
from itertools import combinations, product
from itertools import combinations, product
from time import time
from time import time
import matplotlib.pyplot as plt
import matplotlib.pyplot as plt
from IPython.display import HTML
from IPython.display import HTML
from jupyter_jsmol import JsmolView
from jupyter_jsmol import JsmolView
import pathlib
import pathlib
 
from pathlib import Path
from compressed_sensing.sisso import SissoRegressor
from compressed_sensing.sisso import SissoRegressor
from compressed_sensing.combine_features import combine_features
from compressed_sensing.combine_features import combine_features
from sissopp.py_interface.import_dataframe import get_unit
from sissopp.py_interface.import_dataframe import get_unit
from sissopp.sklearn import SISSORegressor as SISSORegressor_skl
from sissopp.sklearn import SISSORegressor as SISSORegressor_skl
 
from pysr import PySRRegressor
 
from sympy import Abs, root, sign
 
warnings.filterwarnings('ignore')
warnings.filterwarnings('ignore')
from bokeh.io import export_png
from bokeh.io import export_png
 
%% Cell type:code id: tags:
 
``` python
 
@contextlib.contextmanager
 
def cwd(path, mkdir=False, debug=False, clear=True):
 
CWD = os.getcwd()
 
 
if os.path.exists(path) is False and mkdir:
 
os.makedirs(path)
 
 
if debug:
 
os.chdir(path)
 
yield
 
os.chdir(CWD)
 
return
 
 
os.chdir(path)
 
yield
 
os.chdir(CWD)
 
if clear:
 
shutil.rmtree(path)
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
feat_space = FeatureSpace(inputs)
feat_space = FeatureSpace(inputs)
sisso = SISSORegressor(inputs, feat_space)
sisso = SISSORegressor(inputs, feat_space)
 
with cwd(Path("SISSO_training"), mkdir=True):
 
sisso.fit()
sisso.fit()
for i in range(n_nonzero_coefs):
for i in range(n_nonzero_coefs):
print(str(i+1)+'D model')
print(str(i+1)+'D model')
print("RMSE: {:.4} | Descriptor: {}".format(sisso.models[i][0].rmse, sisso.models[i][0]))
print("RMSE: {:.4} | Descriptor: {}".format(sisso.models[i][0].rmse, sisso.models[i][0]))
sisso = SISSORegressor(inputs, feat_space)
sisso = SISSORegressor(inputs, feat_space)
sisso.fit()
with cwd(Path("SISSO_training"), mkdir=True):
 
sisso.fit()
 
for i in range(n_nonzero_coefs):
for i in range(n_nonzero_coefs):
print(str(i+1)+'D model')
print(str(i+1)+'D model')
print("RMSE: {:.4} | Descriptor: {}".format(sisso.models[i][0].rmse, sisso.models[i][0]))
print("RMSE: {:.4} | Descriptor: {}".format(sisso.models[i][0].rmse, sisso.models[i][0]))
df_sisso_cv = df_plus_reduced.drop(columns=["energy_diff"])
df_sisso_cv = df_plus_reduced.drop(columns=["energy_diff"])
for indices_train, index_test in loo.split(P):
with cwd(Path("SISSO_CV"), mkdir=True):
i_cv = index_test[0]
for indices_train, index_test in loo.split(P):
print('%2s) Leave out %s: Ediff_ref = %.3f eV/atom'
i_cv = index_test[0]
% (index_test[0]+1, chemical_formulas[i_cv], P[i_cv]))
print('%2s) Leave out %s: Ediff_ref = %.3f eV/atom'
% (index_test[0]+1, chemical_formulas[i_cv], P[i_cv]))
sisso.fit(df_sisso_cv.iloc[indices_train, :], P[indices_train])
data_dct = {col.split("(")[0].strip(): df_sisso_cv.iloc[i_cv, cc] for cc, col in enumerate(df_sisso_cv.columns)}
sisso.fit(df_sisso_cv.iloc[indices_train, :], P[indices_train])
predicted_value = [models[0].eval(data_dct) for models in sisso.solver.models[:]]
data_dct = {col.split("(")[0].strip(): df_sisso_cv.iloc[i_cv, cc] for cc, col in enumerate(df_sisso_cv.columns)}
P_predict[:, i_cv] = predicted_value
predicted_value = [models[0].eval(data_dct) for models in sisso.solver.models[:]]
for dim in dimensions:
P_predict[:, i_cv] = predicted_value
print('Ediff_predicted(%sD) = %.3f eV/atom' %(dim, predicted_value[dim - 1]))
for dim in dimensions:
print('-----')
print('Ediff_predicted(%sD) = %.3f eV/atom' %(dim, predicted_value[dim - 1]))
 
print('-----')
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
import contextlib
import os
from pathlib import Path
from pysr import PySRRegressor
from sympy import Abs, root, sign
@contextlib.contextmanager
def cwd(path, mkdir=False, debug=False):
CWD = os.getcwd()
if os.path.exists(path) is False and mkdir:
os.makedirs(path)
if debug:
os.chdir(path)
yield
os.chdir(CWD)
return
os.chdir(path)
yield
os.chdir(CWD)
pysr = PySRRegressor(
pysr = PySRRegressor(
niterations=100,
niterations=100,
binary_operators=["+", "-", "/"],
binary_operators=["+", "-", "/"],
P_predict_pysr = []
P_predict_pysr = []
loo = LeaveOneOut()
loo = LeaveOneOut()
for indices_train, index_test in loo.split(P):
with cwd(Path("pySR"), mkdir=True):
pysr_path = f"pySR/{index_test[0]}"
for indices_train, index_test in loo.split(P):
with cwd(pysr_path, mkdir=True):
pysr.fit(pysr_df.iloc[indices_train, :], P[indices_train])
pysr.fit(pysr_df.iloc[indices_train, :], P[indices_train])
P_predict_pysr.append(pysr.predict(pysr_df.iloc[index_test, :])[0])
P_predict_pysr.append(pysr.predict(pysr_df.iloc[index_test, :])[0])
print("%2i Ediff_ref: %.3f, Ediff_pred: %.3f, equation: {%s}"
print("%2i Ediff_ref: %.3f, Ediff_pred: %.3f, equation: {%s}"
``` python
``` python
pysr_path = f"pySR/all_pts"
pysr_path = Path(f"pySR/all_pts")
with cwd(pysr_path, mkdir=True):
with cwd(pysr_path, mkdir=True):
pysr.fit(pysr_df, P)
pysr.fit(pysr_df, P)
print(pysr.get_best().sympy_format)
print(pysr.get_best().sympy_format)
plt.ylabel("Count")
plt.ylabel("Count")
plt.show()
plt.show()
 
%% Cell type:code id: tags:
 
``` python
Loading