Skip to content

Commit

Permalink
Modified the signature of get_sa_coefficients()
Browse files Browse the repository at this point in the history
  • Loading branch information
alongd committed Dec 3, 2024
1 parent 74c1af6 commit 5ba291f
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 9 deletions.
8 changes: 7 additions & 1 deletion t3/simulate/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""

from abc import ABC, abstractmethod
from typing import Optional


class SimulateAdapter(ABC):
Expand All @@ -27,7 +28,12 @@ def simulate(self):
pass

@abstractmethod
def get_sa_coefficients(self):
def get_sa_coefficients(self,
top_SA_species: int = 10,
top_SA_reactions: int = 10,
max_workers: int = 24,
save_yaml: bool = True,
) -> Optional[dict]:
"""
Obtain the sensitivity analysis coefficients.
Expand Down
20 changes: 17 additions & 3 deletions t3/simulate/cantera_constantHP.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from rmgpy.tools.canteramodel import generate_cantera_conditions
from rmgpy.tools.data import GenericData

from arc.common import save_yaml_file

from t3.common import get_observable_label_from_header, get_parameter_from_header
from t3.logger import Logger
from t3.simulate.adapter import SimulateAdapter
Expand Down Expand Up @@ -382,12 +384,23 @@ def simulate(self):

self.all_data.append((time, condition_data, reaction_sensitivity_data, thermodynamic_sensitivity_data))

def get_sa_coefficients(self):
def get_sa_coefficients(self,
top_SA_species: int = 10,
top_SA_reactions: int = 10,
max_workers: int = 24,
save_yaml: bool = True,
) -> Optional[dict]:
"""
Obtain the SA coefficients.
Args:
top_SA_species (int, optional): The number of top sensitive species to return.
top_SA_reactions (int, optional): The number of top sensitive reactions to return.
max_workers (int, optional): The maximal number of workers to use for parallel processing.
save_yaml (bool, optional): Save the SA dictionary to a YAML file.
Returns:
sa_dict (dict): a SA dictionary, whose structure is given in the docstring for T3/t3/main.py
sa_dict (Optional[dict]): a SA dictionary, whose structure is given in the docstring for T3/t3/main.py
"""
sa_dict = {'kinetics': dict(), 'thermo': dict(), 'time': list()}

Expand All @@ -411,7 +424,8 @@ def get_sa_coefficients(self):
sa_dict['thermo'][observable_label] = dict()
parameter = get_parameter_from_header(spc)
sa_dict['thermo'][observable_label][parameter] = spc.data

if save_yaml:
save_yaml_file(path=self.paths['SA dict'], content=sa_dict)
return sa_dict

def get_idt_by_T(self):
Expand Down
20 changes: 18 additions & 2 deletions t3/simulate/cantera_constantTP.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from rmgpy.tools.canteramodel import generate_cantera_conditions
from rmgpy.tools.data import GenericData

from arc.common import save_yaml_file

from t3.logger import Logger
from t3.simulate.adapter import SimulateAdapter
from t3.simulate.factory import register_simulate_adapter
Expand Down Expand Up @@ -381,12 +383,23 @@ def simulate(self):

self.all_data.append((time, condition_data, reaction_sensitivity_data, thermodynamic_sensitivity_data))

def get_sa_coefficients(self):
def get_sa_coefficients(self,
top_SA_species: int = 10,
top_SA_reactions: int = 10,
max_workers: int = 24,
save_yaml: bool = True,
) -> Optional[dict]:
"""
Obtain the SA coefficients.
Args:
top_SA_species (int, optional): The number of top sensitive species to return.
top_SA_reactions (int, optional): The number of top sensitive reactions to return.
max_workers (int, optional): The maximal number of workers to use for parallel processing.
save_yaml (bool, optional): Save the SA dictionary to a YAML file.
Returns:
sa_dict (dict): a SA dictionary, whose structure is given in the docstring for T3/t3/main.py
sa_dict (Optional[dict]): a SA dictionary, whose structure is given in the docstring for T3/t3/main.py
"""
sa_dict = {'kinetics': dict(), 'thermo': dict(), 'time': list()}

Expand Down Expand Up @@ -415,6 +428,9 @@ def get_sa_coefficients(self):
parameter = spc.label.split('[')[2].split(']')[0]
sa_dict['thermo'][observable_label][parameter] = spc.data

if save_yaml:
save_yaml_file(path=self.paths['SA dict'], content=sa_dict)

return sa_dict

def get_idt_by_T(self):
Expand Down
19 changes: 17 additions & 2 deletions t3/simulate/cantera_constantUV.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from rmgpy.tools.canteramodel import generate_cantera_conditions
from rmgpy.tools.data import GenericData

from arc.common import save_yaml_file

from t3.logger import Logger
from t3.simulate.adapter import SimulateAdapter
from t3.simulate.factory import register_simulate_adapter
Expand Down Expand Up @@ -381,12 +383,23 @@ def simulate(self):

self.all_data.append((time, condition_data, reaction_sensitivity_data, thermodynamic_sensitivity_data))

def get_sa_coefficients(self):
def get_sa_coefficients(self,
top_SA_species: int = 10,
top_SA_reactions: int = 10,
max_workers: int = 24,
save_yaml: bool = True,
) -> Optional[dict]:
"""
Obtain the SA coefficients.
Args:
top_SA_species (int, optional): The number of top sensitive species to return.
top_SA_reactions (int, optional): The number of top sensitive reactions to return.
max_workers (int, optional): The maximal number of workers to use for parallel processing.
save_yaml (bool, optional): Save the SA dictionary to a YAML file.
Returns:
sa_dict (dict): a SA dictionary, whose structure is given in the docstring for T3/t3/main.py
sa_dict (Optional[dict]): a SA dictionary, whose structure is given in the docstring for T3/t3/main.py
"""
sa_dict = {'kinetics': dict(), 'thermo': dict(), 'time': list()}

Expand Down Expand Up @@ -415,6 +428,8 @@ def get_sa_coefficients(self):
parameter = spc.label.split('[')[2].split(']')[0]
sa_dict['thermo'][observable_label][parameter] = spc.data

if save_yaml:
save_yaml_file(path=self.paths['SA dict'], content=sa_dict)
return sa_dict

def get_idt_by_T(self):
Expand Down
17 changes: 16 additions & 1 deletion t3/simulate/rmg_constantTP.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
from rmgpy.tools.loader import load_rmg_py_job
from rmgpy.tools.plot import plot_sensitivity

from arc.common import save_yaml_file

from t3.common import get_chem_to_rmg_rxn_index_map, get_species_by_label, get_values_within_range, \
get_observable_label_from_header, get_parameter_from_header, time_lapse
from t3.simulate.adapter import SimulateAdapter
Expand Down Expand Up @@ -224,10 +226,21 @@ def simulate(self):

self.logger.info(f'Simulation via RMG completed, execution time: {time_lapse(tic)}')

def get_sa_coefficients(self) -> Optional[dict]:
def get_sa_coefficients(self,
top_SA_species: int = 10,
top_SA_reactions: int = 10,
max_workers: int = 24,
save_yaml: bool = True,
) -> Optional[dict]:
"""
Obtain the SA coefficients.
Args:
top_SA_species (int, optional): The number of top sensitive species to return.
top_SA_reactions (int, optional): The number of top sensitive reactions to return.
max_workers (int, optional): The maximal number of workers to use for parallel processing.
save_yaml (bool, optional): Save the SA dictionary to a YAML file.
Returns:
sa_dict (Optional[dict]): An SA dictionary, structure is given in the docstring for T3/t3/main.py
"""
Expand Down Expand Up @@ -265,6 +278,8 @@ def get_sa_coefficients(self) -> Optional[dict]:
parameter = chem_to_rmg_rxn_index_map[int(parameter)] \
if all(c.isdigit() for c in parameter) else parameter
sa_dict[sa_type][observable_label][parameter] = df[header].values
if save_yaml:
save_yaml_file(path=self.paths['SA dict'], content=sa_dict)
return sa_dict

def generate_rmg_reactors_for_simulation(self) -> dict:
Expand Down

0 comments on commit 5ba291f

Please sign in to comment.