From 98347f3c9e6f5e3733f226af8756d28c04e35b9c Mon Sep 17 00:00:00 2001 From: Alin Marin Elena Date: Sat, 9 Nov 2024 19:37:47 +0000 Subject: [PATCH 1/2] use .4g as format gives better float representation for numbers in training, especially loss --- mace/tools/train.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/mace/tools/train.py b/mace/tools/train.py index 3c6b8325..c4420f39 100644 --- a/mace/tools/train.py +++ b/mace/tools/train.py @@ -60,7 +60,7 @@ def valid_err_log( error_e = eval_metrics["rmse_e_per_atom"] * 1e3 error_f = eval_metrics["rmse_f"] * 1e3 logging.info( - f"{inintial_phrase}: head: {valid_loader_name}, loss={valid_loss:8.8f}, RMSE_E_per_atom={error_e:8.2f} meV, RMSE_F={error_f:8.2f} meV / A" + f"{inintial_phrase}: head: {valid_loader_name}, loss={valid_loss:.4g}, RMSE_E_per_atom={error_e:.4g} meV, RMSE_F={error_f:.4g} meV / A" ) elif ( log_errors == "PerAtomRMSEstressvirials" @@ -70,7 +70,7 @@ def valid_err_log( error_f = eval_metrics["rmse_f"] * 1e3 error_stress = eval_metrics["rmse_stress"] * 1e3 logging.info( - f"{inintial_phrase}: head: {valid_loader_name}, loss={valid_loss:8.8f}, RMSE_E_per_atom={error_e:8.2f} meV, RMSE_F={error_f:8.2f} meV / A, RMSE_stress={error_stress:8.2f} meV / A^3", + f"{inintial_phrase}: head: {valid_loader_name}, loss={valid_loss:.4g}, RMSE_E_per_atom={error_e:.4g} meV, RMSE_F={error_f:.4g} meV / A, RMSE_stress={error_stress:.4g} meV / A^3", ) elif ( log_errors == "PerAtomRMSEstressvirials" @@ -80,7 +80,7 @@ def valid_err_log( error_f = eval_metrics["rmse_f"] * 1e3 error_virials = eval_metrics["rmse_virials_per_atom"] * 1e3 logging.info( - f"{inintial_phrase}: head: {valid_loader_name}, loss={valid_loss:8.8f}, RMSE_E_per_atom={error_e:8.2f} meV, RMSE_F={error_f:8.2f} meV / A, RMSE_virials_per_atom={error_virials:8.2f} meV", + f"{inintial_phrase}: head: {valid_loader_name}, loss={valid_loss:.4g}, RMSE_E_per_atom={error_e:.4g} meV, RMSE_F={error_f:.4g} meV / A, RMSE_virials_per_atom={error_virials:.4g} meV", ) elif ( log_errors == "PerAtomMAEstressvirials" @@ -90,7 +90,7 @@ def valid_err_log( error_f = eval_metrics["mae_f"] * 1e3 error_stress = eval_metrics["mae_stress"] * 1e3 logging.info( - f"{inintial_phrase}: loss={valid_loss:8.8f}, MAE_E_per_atom={error_e:8.2f} meV, MAE_F={error_f:8.2f} meV / A, MAE_stress={error_stress:8.2f} meV / A^3" + f"{inintial_phrase}: loss={valid_loss:.4g}, MAE_E_per_atom={error_e:.4g} meV, MAE_F={error_f:.4g} meV / A, MAE_stress={error_stress:.4g} meV / A^3" ) elif ( log_errors == "PerAtomMAEstressvirials" @@ -100,37 +100,37 @@ def valid_err_log( error_f = eval_metrics["mae_f"] * 1e3 error_virials = eval_metrics["mae_virials"] * 1e3 logging.info( - f"{inintial_phrase}: loss={valid_loss:8.8f}, MAE_E_per_atom={error_e:8.2f} meV, MAE_F={error_f:8.2f} meV / A, MAE_virials={error_virials:8.2f} meV" + f"{inintial_phrase}: loss={valid_loss:.4g}, MAE_E_per_atom={error_e:.4g} meV, MAE_F={error_f:.4g} meV / A, MAE_virials={error_virials:.4g} meV" ) elif log_errors == "TotalRMSE": error_e = eval_metrics["rmse_e"] * 1e3 error_f = eval_metrics["rmse_f"] * 1e3 logging.info( - f"{inintial_phrase}: head: {valid_loader_name}, loss={valid_loss:8.8f}, RMSE_E={error_e:8.2f} meV, RMSE_F={error_f:8.2f} meV / A", + f"{inintial_phrase}: head: {valid_loader_name}, loss={valid_loss:.4g}, RMSE_E={error_e:.4g} meV, RMSE_F={error_f:.4g} meV / A", ) elif log_errors == "PerAtomMAE": error_e = eval_metrics["mae_e_per_atom"] * 1e3 error_f = eval_metrics["mae_f"] * 1e3 logging.info( - f"{inintial_phrase}: head: {valid_loader_name}, loss={valid_loss:8.8f}, MAE_E_per_atom={error_e:8.2f} meV, MAE_F={error_f:8.2f} meV / A", + f"{inintial_phrase}: head: {valid_loader_name}, loss={valid_loss:.4g}, MAE_E_per_atom={error_e:.4g} meV, MAE_F={error_f:.4g} meV / A", ) elif log_errors == "TotalMAE": error_e = eval_metrics["mae_e"] * 1e3 error_f = eval_metrics["mae_f"] * 1e3 logging.info( - f"{inintial_phrase}: head: {valid_loader_name}, loss={valid_loss:8.8f}, MAE_E={error_e:8.2f} meV, MAE_F={error_f:8.2f} meV / A", + f"{inintial_phrase}: head: {valid_loader_name}, loss={valid_loss:.4g}, MAE_E={error_e:.4g} meV, MAE_F={error_f:.4g} meV / A", ) elif log_errors == "DipoleRMSE": error_mu = eval_metrics["rmse_mu_per_atom"] * 1e3 logging.info( - f"{inintial_phrase}: head: {valid_loader_name}, loss={valid_loss:8.8f}, RMSE_MU_per_atom={error_mu:8.2f} mDebye", + f"{inintial_phrase}: head: {valid_loader_name}, loss={valid_loss:.4g}, RMSE_MU_per_atom={error_mu:.4g} mDebye", ) elif log_errors == "EnergyDipoleRMSE": error_e = eval_metrics["rmse_e_per_atom"] * 1e3 error_f = eval_metrics["rmse_f"] * 1e3 error_mu = eval_metrics["rmse_mu_per_atom"] * 1e3 logging.info( - f"{inintial_phrase}: head: {valid_loader_name}, loss={valid_loss:8.8f}, RMSE_E_per_atom={error_e:8.2f} meV, RMSE_F={error_f:8.2f} meV / A, RMSE_Mu_per_atom={error_mu:8.2f} mDebye", + f"{inintial_phrase}: head: {valid_loader_name}, loss={valid_loss:.4g}, RMSE_E_per_atom={error_e:.4g} meV, RMSE_F={error_f:.4g} meV / A, RMSE_Mu_per_atom={error_mu:.4g} mDebye", ) From 7eb12b77fbf56ce0b51cda44db2fc52b6121b636 Mon Sep 17 00:00:00 2001 From: alin m elena Date: Thu, 14 Nov 2024 09:24:32 +0000 Subject: [PATCH 2/2] format results table too to .4g --- mace/tools/tables_utils.py | 74 +++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/mace/tools/tables_utils.py b/mace/tools/tables_utils.py index 07f41401..a5e4eb30 100644 --- a/mace/tools/tables_utils.py +++ b/mace/tools/tables_utils.py @@ -127,18 +127,18 @@ def create_error_table( table.add_row( [ name, - f"{metrics['rmse_e'] * 1000:8.1f}", - f"{metrics['rmse_f'] * 1000:8.1f}", - f"{metrics['rel_rmse_f']:8.2f}", + f"{metrics['rmse_e'] * 1000:.4g}", + f"{metrics['rmse_f'] * 1000:.4g}", + f"{metrics['rel_rmse_f']:.4g}", ] ) elif table_type == "PerAtomRMSE": table.add_row( [ name, - f"{metrics['rmse_e_per_atom'] * 1000:8.1f}", - f"{metrics['rmse_f'] * 1000:8.1f}", - f"{metrics['rel_rmse_f']:8.2f}", + f"{metrics['rmse_e_per_atom'] * 1000:.4g}", + f"{metrics['rmse_f'] * 1000:.4g}", + f"{metrics['rel_rmse_f']:.4g}", ] ) elif ( @@ -148,10 +148,10 @@ def create_error_table( table.add_row( [ name, - f"{metrics['rmse_e_per_atom'] * 1000:8.1f}", - f"{metrics['rmse_f'] * 1000:8.1f}", - f"{metrics['rel_rmse_f']:8.2f}", - f"{metrics['rmse_stress'] * 1000:8.1f}", + f"{metrics['rmse_e_per_atom'] * 1000:.4g}", + f"{metrics['rmse_f'] * 1000:.4g}", + f"{metrics['rel_rmse_f']:.4g}", + f"{metrics['rmse_stress'] * 1000:.4g}", ] ) elif ( @@ -161,10 +161,10 @@ def create_error_table( table.add_row( [ name, - f"{metrics['rmse_e_per_atom'] * 1000:8.1f}", - f"{metrics['rmse_f'] * 1000:8.1f}", - f"{metrics['rel_rmse_f']:8.2f}", - f"{metrics['rmse_virials'] * 1000:8.1f}", + f"{metrics['rmse_e_per_atom'] * 1000:.4g}", + f"{metrics['rmse_f'] * 1000:.4g}", + f"{metrics['rel_rmse_f']:.4g}", + f"{metrics['rmse_virials'] * 1000:.4g}", ] ) elif ( @@ -174,10 +174,10 @@ def create_error_table( table.add_row( [ name, - f"{metrics['mae_e_per_atom'] * 1000:8.1f}", - f"{metrics['mae_f'] * 1000:8.1f}", - f"{metrics['rel_mae_f']:8.2f}", - f"{metrics['mae_stress'] * 1000:8.1f}", + f"{metrics['mae_e_per_atom'] * 1000:.4g}", + f"{metrics['mae_f'] * 1000:.4g}", + f"{metrics['rel_mae_f']:.4g}", + f"{metrics['mae_stress'] * 1000:.4g}", ] ) elif ( @@ -187,55 +187,55 @@ def create_error_table( table.add_row( [ name, - f"{metrics['mae_e_per_atom'] * 1000:8.1f}", - f"{metrics['mae_f'] * 1000:8.1f}", - f"{metrics['rel_mae_f']:8.2f}", - f"{metrics['mae_virials'] * 1000:8.1f}", + f"{metrics['mae_e_per_atom'] * 1000:.4g}", + f"{metrics['mae_f'] * 1000:.4g}", + f"{metrics['rel_mae_f']:.4g}", + f"{metrics['mae_virials'] * 1000:.4g}", ] ) elif table_type == "TotalMAE": table.add_row( [ name, - f"{metrics['mae_e'] * 1000:8.1f}", - f"{metrics['mae_f'] * 1000:8.1f}", - f"{metrics['rel_mae_f']:8.2f}", + f"{metrics['mae_e'] * 1000:.4g}", + f"{metrics['mae_f'] * 1000:.4g}", + f"{metrics['rel_mae_f']:.4g}", ] ) elif table_type == "PerAtomMAE": table.add_row( [ name, - f"{metrics['mae_e_per_atom'] * 1000:8.1f}", - f"{metrics['mae_f'] * 1000:8.1f}", - f"{metrics['rel_mae_f']:8.2f}", + f"{metrics['mae_e_per_atom'] * 1000:.4g}", + f"{metrics['mae_f'] * 1000:.4g}", + f"{metrics['rel_mae_f']:.4g}", ] ) elif table_type == "DipoleRMSE": table.add_row( [ name, - f"{metrics['rmse_mu_per_atom'] * 1000:8.2f}", - f"{metrics['rel_rmse_mu']:8.1f}", + f"{metrics['rmse_mu_per_atom'] * 1000:.4g}", + f"{metrics['rel_rmse_mu']:.4g}", ] ) elif table_type == "DipoleMAE": table.add_row( [ name, - f"{metrics['mae_mu_per_atom'] * 1000:8.2f}", - f"{metrics['rel_mae_mu']:8.1f}", + f"{metrics['mae_mu_per_atom'] * 1000:.4g}", + f"{metrics['rel_mae_mu']:.4g}", ] ) elif table_type == "EnergyDipoleRMSE": table.add_row( [ name, - f"{metrics['rmse_e_per_atom'] * 1000:8.1f}", - f"{metrics['rmse_f'] * 1000:8.1f}", - f"{metrics['rel_rmse_f']:8.1f}", - f"{metrics['rmse_mu_per_atom'] * 1000:8.1f}", - f"{metrics['rel_rmse_mu']:8.1f}", + f"{metrics['rmse_e_per_atom'] * 1000:.4g}", + f"{metrics['rmse_f'] * 1000:.4g}", + f"{metrics['rel_rmse_f']:.4g}", + f"{metrics['rmse_mu_per_atom'] * 1000:.4g}", + f"{metrics['rel_rmse_mu']:.4g}", ] ) return table