def doc(attribute=None, list_supported=False, init_seq=False, config=False, **kwargs): """ Quick documentation from command-line. """ system = System() if attribute is not None: if attribute in system.__dict__ and hasattr(system.__dict__[attribute], 'doc'): if init_seq is True: system.__dict__[attribute].get_init_order() return logger.info(system.__dict__[attribute].doc()) else: logger.error('Model <%s> does not exist.', attribute) elif list_supported is True: logger.info(system.supported_models()) else: logger.info( 'info: no option specified. Use \'andes doc -h\' for help.')
def save_conf(config_path=None, overwrite=None): """ Save the Andes config to a file at the path specified by ``save_config``. The save action will not run if ``save_config = ''``. Parameters ---------- config_path : None or str, optional, ('' by default) Path to the file to save the config file. If the path is an emtpy string, the save action will not run. Save to `~/.andes/andes.conf` if ``None``. Returns ------- bool ``True`` is the save action is run. ``False`` otherwise. """ ret = False # no ``--save-config `` if config_path == '': return ret if config_path is not None and os.path.isdir(config_path): config_path = os.path.join(config_path, 'andes.rc') ps = System() ps.save_config(config_path, overwrite=overwrite) ret = True return ret
def prepare(quick=False, incremental=False, cli=False, full=False, **kwargs): """ Run code generation. Warnings -------- The default behavior has changed since v1.0.8: when `cli` is `True` and `full` is not `True`, quick code generation will be used. Returns ------- System object if `cli` is `False`; exit_code 0 otherwise. """ # use `quick` for cli if `full` is not enforced, # because the LaTeX code gen is usually discarded in CLI. if cli is True: if not full: quick = True if full is True: quick = False system = System() system.prepare(quick=quick, incremental=incremental) if cli is True: return 0 else: return system
def setUp(self) -> None: self.ss = System() self.ss.undill_calls() # load from excel file xlsx.read(self.ss, get_case('5bus/pjm5bus.xlsx')) self.ss.setup()
class Test5Bus(unittest.TestCase): def setUp(self) -> None: self.ss = System() self.ss.undill_calls() # load from excel file xlsx.read(self.ss, get_case('5bus/pjm5bus.xlsx')) self.ss.setup() def test_names(self): self.assertTrue('Bus' in self.ss.models) self.assertTrue('PQ' in self.ss.models) def test_count(self): self.assertEqual(self.ss.Bus.n, 5) self.assertEqual(self.ss.PQ.n, 3) self.assertEqual(self.ss.PV.n, 3) self.assertEqual(self.ss.Slack.n, 1) self.assertEqual(self.ss.Line.n, 7) self.assertEqual(self.ss.GENCLS.n, 4) self.assertEqual(self.ss.TG2.n, 4) def test_idx(self): self.assertSequenceEqual(self.ss.Bus.idx, [0, 1, 2, 3, 4]) self.assertSequenceEqual(self.ss.Area.idx, [1, 2, 3]) def test_pflow(self): self.ss.PFlow.run() self.ss.PFlow.newton_krylov() def test_tds_init(self): self.ss.PFlow.run() self.ss.TDS.run([0, 20])
def prepare(quick=False, **kwargs): t0, _ = elapsed() logger.info('Numeric code preparation started...') system = System() system.prepare(quick=quick) _, s = elapsed(t0) logger.info(f'Successfully generated numerical code in {s}.') return True
class TestKundur2Area(unittest.TestCase): """ Test Kundur's 2-area system """ def setUp(self) -> None: self.ss = System() self.ss.undill_calls() xlsx.read(self.ss, get_case('kundur/kundur_full.xlsx')) self.ss.setup() def test_tds_init(self): self.ss.PFlow.run() self.ss.TDS.run([0, 20])
def doc(attribute=None, list_supported=False, **kwargs): system = System() if attribute is not None: if attribute in system.__dict__ and hasattr(system.__dict__[attribute], 'doc'): logger.info(system.__dict__[attribute].doc()) else: logger.error(f'Model <{attribute}> does not exist.') elif list_supported is True: logger.info(system.supported_models()) else: logger.info( 'info: no option specified. Use \'andes doc -h\' for help.')
def edit_conf(edit_config: Optional[Union[str, bool]] = ''): """ Edit the Andes config file which occurs first in the search path. Parameters ---------- edit_config : bool If ``True``, try to open up an editor and edit the config file. Otherwise returns. Returns ------- bool ``True`` is a config file is found and an editor is opened. ``False`` if ``edit_config`` is False. """ ret = False # no `edit-config` supplied if edit_config == '': return ret conf_path = get_config_path() if conf_path is None: logger.info('Config file does not exist. Automatically saving.') system = System() conf_path = system.save_config() logger.info('Editing config file "%s"', conf_path) editor = '' if edit_config is not None: # use `edit_config` as default editor editor = edit_config else: # use the following default editors if platform.system() == 'Linux': editor = os.environ.get('EDITOR', 'vim') elif platform.system() == 'Darwin': editor = os.environ.get('EDITOR', 'vim') elif platform.system() == 'Windows': editor = 'notepad.exe' editor_cmd = editor.split() editor_cmd.append(conf_path) call(editor_cmd) ret = True return ret
def prepare(quick=False, incremental=False, cli=False, **kwargs): """ Run code generation. Returns ------- System object """ t0, _ = elapsed() logger.info('Numeric code generation started...') system = System() system.prepare(quick=quick, incremental=incremental) _, s = elapsed(t0) logger.info(f'Successfully generated numerical code in {s}.') if cli is True: return 0 else: return system
def test_sort_models(self): """ Test sort_models. """ system = System() dirname = os.path.dirname(__file__) with open(f'{dirname}/../andes/io/psse-dyr.yaml', 'r') as f: dyr_yaml = yaml.full_load(f) psse.sort_psse_models(dyr_yaml, system)
def prepare(quick=False, incremental=False, models=None, precompile=False, nomp=False, **kwargs): """ Run code generation. Parameters ---------- full : bool True to run full prep with formatted equations. Useful in interactive mode and during document generation. ncpu : int Number of cores to be used for parallel processing. cli : bool True to indicate running from CLI. It will set `quick` to True if not `full`. precompile : bool True to compile model function calls after code generation. Warnings -------- The default behavior has changed since v1.0.8: when `cli` is `True` and `full` is not `True`, quick code generation will be used. Returns ------- System object if `cli` is `False`; exit_code 0 otherwise. """ # use `quick` for cli if `full` is not enforced, # because the LaTeX code gen is usually discarded in CLI. cli = kwargs.get("cli", False) full = kwargs.get("full", False) ncpu = kwargs.get("ncpu", os.cpu_count()) if cli is True: if not full: quick = True if full is True: quick = False # run code generation system = System(options=kwargs, no_undill=True) system.prepare(quick=quick, incremental=incremental, models=models, nomp=nomp, ncpu=ncpu) # compile model function calls if precompile: system.precompile(models, nomp=nomp, ncpu=ncpu) if cli is True: return 0 else: return system
""" This file is used to generate reStructuredText tables for Group and Model references """ import dill from andes.system import System dill.settings['recurse'] = True ss = System() ss.prepare() out = '' out += '.. _modelref:\n\n' out += '********************************************************************************\n' out += 'Model References\n' out += '********************************************************************************\n' out += '\n' for group in ss.groups.values(): out += group.doc_all(export='rest') with open('modelref.rst', 'w') as f: f.write(out)
def setUp(self) -> None: self.ss = System() system = self.ss system.prepare()
def setUp(self) -> None: self.ss = System() self.ss.undill_calls() xlsx.read(self.ss, get_case('kundur/kundur_full.xlsx')) self.ss.setup()