geff.models
This module contains pre-defined GEF models.
Currently, the following models are implemented:
- 'pai': pure axion inflation
- 'fai_basic': fermionic axion inflation (without accounting for fermion $k$-dependence)
- 'fai_kh': fermionic axion inflation (accounting for fermion $k$-dependence using $k_h$)
Execute these models by calling GEFF.gef.GEF with its name and settings.
1""" 2This module contains pre-defined GEF models. 3 4Currently, the following models are implemented: 51. **'pai'**: pure axion inflation 62. **'fai_basic'**: fermionic axion inflation (without accounting for fermion $k$-dependence) 73. **'fai_kh'**: fermionic axion inflation (accounting for fermion $k$-dependence using $k_h$) 8 9Execute these models by calling `GEFF.gef.GEF` with its name and settings. 10""" 11import importlib 12import os 13 14def load_model(model : str, user_settings : dict={}): 15 """ 16 Import and execute a module defining a GEF model. 17 18 Parameters 19 ---------- 20 model : str 21 The name of the GEF model or a full dotted import path (e.g., "path.to.module"). 22 user_settings : dict 23 A dictionary containing updated settings for the module. 24 25 Returns 26 ------- 27 ModuleType 28 The configured module. 29 """ 30 31 # if model is astring, load ./models/{name}.py 32 current_dir = os.path.dirname(os.path.abspath(__file__)) 33 modelpath = os.path.join(current_dir, f"{model}.py") 34 35 if os.path.exists(modelpath): 36 spec = importlib.util.spec_from_file_location(model, modelpath) 37 mod = importlib.util.module_from_spec(spec) 38 spec.loader.exec_module(mod) 39 40 else: 41 # if model is not a string, try loading it directly as a module 42 try: 43 mod = model 44 except ImportError as e: 45 raise FileNotFoundError( 46 f"No model file found at '{modelpath}' and failed to import '{model}'" 47 ) from e 48 49 if hasattr(mod, "settings") and isinstance(user_settings, dict): 50 for key, item in user_settings.items(): 51 if key in mod.settings: 52 mod.settings[key] = item 53 print(f"Updating '{key}' to '{item}'.") 54 else: 55 print(f"Ignoring unknown model setting '{key}'.") 56 mod.interpret_settings() 57 58 return mod
def
load_model(model: str, user_settings: dict = {}):
15def load_model(model : str, user_settings : dict={}): 16 """ 17 Import and execute a module defining a GEF model. 18 19 Parameters 20 ---------- 21 model : str 22 The name of the GEF model or a full dotted import path (e.g., "path.to.module"). 23 user_settings : dict 24 A dictionary containing updated settings for the module. 25 26 Returns 27 ------- 28 ModuleType 29 The configured module. 30 """ 31 32 # if model is astring, load ./models/{name}.py 33 current_dir = os.path.dirname(os.path.abspath(__file__)) 34 modelpath = os.path.join(current_dir, f"{model}.py") 35 36 if os.path.exists(modelpath): 37 spec = importlib.util.spec_from_file_location(model, modelpath) 38 mod = importlib.util.module_from_spec(spec) 39 spec.loader.exec_module(mod) 40 41 else: 42 # if model is not a string, try loading it directly as a module 43 try: 44 mod = model 45 except ImportError as e: 46 raise FileNotFoundError( 47 f"No model file found at '{modelpath}' and failed to import '{model}'" 48 ) from e 49 50 if hasattr(mod, "settings") and isinstance(user_settings, dict): 51 for key, item in user_settings.items(): 52 if key in mod.settings: 53 mod.settings[key] = item 54 print(f"Updating '{key}' to '{item}'.") 55 else: 56 print(f"Ignoring unknown model setting '{key}'.") 57 mod.interpret_settings() 58 59 return mod
Import and execute a module defining a GEF model.
Parameters
- model (str): The name of the GEF model or a full dotted import path (e.g., "path.to.module").
- user_settings (dict): A dictionary containing updated settings for the module.
Returns
- ModuleType: The configured module.