How to use the andes.utils.elapsed function in andes

To help you get started, we’ve selected a few andes examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cuihantao / andes / andes / routines / tds.py View on Github external
while time() - rt_end < 0:
                        sleep(1e-5)

        if config.qrt:
            logger.debug('RT headroom time: {} s.'.format(str(self.headroom)))

        if self.t != config.tf:
            logger.error('Reached minimum time step. Convergence is not likely.')
            ret = False
        else:
            ret = True

        if system.config.dime_enable:
            system.streaming.finalize()

        _, s = elapsed(t0)

        if ret is True:
            logger.info(' Time domain simulation finished in {:s}.'.format(s))
        else:
            logger.info(' Time domain simulation failed in {:s}.'.format(s))

        self.success = ret
        self.dump_results(success=self.success)

        return ret
github cuihantao / andes / andes / routines / tds.py View on Github external
system.xy_addr1()

        # Assign variable names for bus injections and line flows if enabled
        system.varname.resize_for_flows()
        system.varname.bus_line_names()

        # Reshape dae to retain psstower flow solutions
        system.dae.init1()

        # Initialize post-powerflow device variables
        for device, init1 in zip(system.devman.devices, system.call.init1):
            if init1:
                system.__dict__[device].init1(system.dae)

        system.call.int()
        t, s = elapsed(t)

        if system.dae.n:
            logger.debug('Dynamic models initialized in {:s}.'.format(s))
        else:
            logger.debug('No dynamic model loaded.')

        # system.dae flags initialize
        system.dae.factorize = True
        system.dae.mu = 1.0
        system.dae.kg = 0.0

        self.initialized = True

        return True
github cuihantao / andes / andes / filters / __init__.py View on Github external
def parse(system):
    """
    Parse input file with the given format in system.files.input_format
    """

    t, _ = elapsed()

    input_format = system.files.input_format
    add_format = system.files.add_format
    # exit when no input format is given
    if not input_format:
        logger.error(
            'No input format found. Specify or guess a format before parsing.')
        return False

    # exit if the format parser could not be imported
    try:
        parser = importlib.import_module('.' + input_format, __name__)
        dmparser = importlib.import_module('.' + 'dome', __name__)
        if add_format:
            addparser = importlib.import_module('.' + add_format, __name__)
    except ImportError:
github cuihantao / andes / andes / main.py View on Github external
nlines = 40
            ps = pstats.Stats(pr, stream=sys.stdout).sort_stats('cumtime')
            ps.print_stats(nlines)
            logger.info(s.getvalue())
            s.close()
        else:
            s = open(system.files.prof, 'w')
            nlines = 999
            ps = pstats.Stats(pr, stream=s).sort_stats('cumtime')
            ps.print_stats(nlines)
            s.close()
            logger.info('cProfile results for job{:s} written.'.format(
                ' ' + str(pid) if pid >= 0 else ''))

    if pid >= 0:
        _, s = elapsed(t0)
        msg_finish = 'Process {:d} finished in {:s}.'.format(pid, s)
        logger.info(msg_finish)
        print(msg_finish)

    return system
github cuihantao / andes / andes / filters / __init__.py View on Github external
logger.error(
                'Error parsing addfile {:s} with {:s} format parser.'.format(
                    system.files.addfile, input_format))
            return False

    # Try parsing the dynfile with dm filter
    if system.files.dynfile:
        logger.info('Parsing input file {:s}.'.format(
            system.files.dynfile))
        if not dmparser.read(system.files.dynfile, system):
            logger.error(
                'Error parsing dynfile {:s} with dm format parser.'.format(
                    system.files.dynfile))
            return False

    _, s = elapsed(t)
    logger.debug('Case file {:s} parsed in {:s}.'.format(
        system.files.fullname, s))

    return True
github cuihantao / andes / andes / main.py View on Github external
routine : Iterable, optional
        A list of routines to run in sequence (``('pflow')`` as default)

    pid : idx, optional
        Process idx of the current run

    kwargs : dict, optional
        Other keyword arguments

    Returns
    -------
    PowerSystem
        Andes PowerSystem object

    """
    t0, _ = elapsed()

    # enable profiler if requested
    pr = cProfile.Profile()
    if profile is True:
        pr.enable()

    system = PowerSystem(case, **kwargs)

    # guess format and parse data
    if not filters.guess(system):
        return

    if not filters.parse(system):
        return

    # dump system as raw file if requested
github cuihantao / andes / andes / filters / __init__.py View on Github external
def dump_raw(system):
    t, _ = elapsed()

    outfile = system.files.dump_raw
    dmparser = importlib.import_module('.' + 'dome', __name__)

    ret = dmparser.write(outfile, system)

    _, s = elapsed(t)
    if ret:
        logger.info('Raw file dump {:s} written in {:s}.'.format(
            system.files.dump_raw, s))
    else:
        logger.error('Dump raw file failed.')
github cuihantao / andes / andes / routines / tds.py View on Github external
except ValueError:
                    self.t = config.tf
                    ret = False
                    break

            self.step += 1
            self.compute_flows()
            system.varout.store(self.t, self.step)
            self.streaming_step()

            # plot variables and display iteration status
            perc = max(min((self.t - config.t0) / (config.tf - config.t0) * 100, 100), 0)

            # show iteration info every 30 seconds or every 20%

            t2, _ = elapsed(t1)
            if t2 - t1 >= 30:
                t1 = t2
                logger.info(' ({:.0f}%) time = {:.4f}s, step = {}, niter = {}'
                            .format(100 * self.t / config.tf, self.t, self.step,
                                    self.niter))

            if perc > self.next_pc or self.t == config.tf:
                self.next_pc += 20
                logger.info(' ({:.0f}%) time = {:.4f}s, step = {}, niter = {}'
                            .format(100 * self.t / config.tf, self.t, self.step, self.niter))

            # compute max rotor angle difference
            # diff_max = anglediff()

            # quasi-real-time check and wait
            rt_end = config.qrtstart + (self.t - config.t0) * config.kqrt
github cuihantao / andes / andes / routines / pflow.py View on Github external
# initialization Y matrix and inital guess
        if not self.pre():
            return False

        t, _ = elapsed()

        # call solution methods
        if self.config.method == 'NR':
            ret = self.newton()
        elif self.config.method == 'DCPF':
            ret = self.dcpf()
        elif self.config.method in ('FDPF', 'FDBX', 'FDXB'):
            ret = self.fdpf()

        self.post()
        _, s = elapsed(t)

        if self.solved:
            logger.info(' Solution converged in {} in {} iterations'.format(s, self.niter))
        else:
            logger.warning(' Solution failed in {} in {} iterations'.format(s,
                           self.niter))
        return ret