Ejemplo n.º 1
0
Archivo: parser.py Proyecto: tdi/pyPEPA
 def __init__(self):
     self.log_pa = init_log()
     self._processes = {}
     self._var_stack = {}
     self._actions = []
     self._seen = {}
     self.systemeq = None
     self.rate_parser = RateParser()
Ejemplo n.º 2
0
 def __init__(self, rates):
     self._visitstack= []
     self.graph = ModelSSGraph()
     self.log = init_log()
     self.seq_components = {}
     self.shared_actions = {}
     self.operators = []
     self.components = []
     self.ss = StateSpace()
     self.rates = rates
Ejemplo n.º 3
0
 def __init__(self, **kwargs):
     """ Create PEPA model instance and fill the fields """
     self.args = kwargs
     self.processes = {}
     self.systemeq = None
     self.rate_definitions = {}
     self.components = {}
     # from BU alg, get rid of it
     self.tw = None
     self.ss = None
     self.log = init_log()
     self._solver = None
     self.log.info("Starting got args {}".format(kwargs))
     self.name = os.path.basename(kwargs["file"])
     self._parse_read_model(kwargs["file"])
Ejemplo n.º 4
0
 def __init__(self, **kwargs):
     """ Create PEPA model instance and fill the fields """
     self.args = kwargs
     self.processes = {}
     self.systemeq = None
     self.rate_definitions = {}
     self.components = {}
     # from BU alg, get rid of it
     self.tw = None
     self.ss = None
     self.log = init_log()
     self._solver = None
     self.log.info("Starting got args {}".format(kwargs))
     self.name = os.path.basename(kwargs["file"])
     self._parse_read_model(kwargs["file"])
Ejemplo n.º 5
0
    def __init__(self, **kwargs):
        """ Create PEPA model instance and fill the fields """
        self.args = kwargs
        # Set up model_filename and model_string depending upon which is
        # is set in the arguments.
        self.model_filename = kwargs.get("file", None)
        self.model_string = kwargs.get("modelstring", None)
        self.name = os.path.basename(kwargs.get("name", self.model_filename))
        # In case the name is still None, we set it to a default
        if self.name == None:
          self.name = "model"

        self.processes = {}
        self.systemeq = None
        self.rate_definitions = {}
        self.components = {}
        # from BU alg, get rid of it
        self.tw = None
        self.ss = None
        self.log = init_log()
        self._solver = None
        self.log.info("Starting got args {}".format(kwargs))
        self._parse_model()
Ejemplo n.º 6
0
 def __init__(self):
     self.log_pa = init_log()
     self._processes = {}
     self._var_stack = {}
     self._actions = []
     self.systemeq = None
Ejemplo n.º 7
0
def main():
    parser = argparse.ArgumentParser(
        description="pypepa v{},"
        " author {}, {}".format(__version__, __author__, __email__))
    gen_args = parser.add_argument_group("General", "General arguments")
    gen_args.add_argument("--log",
                          action="store",
                          dest="loglevel",
                          choices=["DEBUG", "INFO", "ERROR", "NONE"],
                          help="logging level",
                          default="NONE",
                          type=str)
    sol_args = parser.add_argument_group("Solution",
                                         "Solution related commands")
    exp_args = parser.add_argument_group("Experimentations",
                                         "Experimentations")

    sol_args.add_argument("-s",
                          "--solver",
                          action="store",
                          dest="solver",
                          type=str,
                          choices=['direct', 'sparse'],
                          help="choose solver type DEFAULT: sparse",
                          default="sparse")
    output_args = parser.add_argument_group("Output", "Output based options")
    parser.add_argument("file", help="path to the model file")
    output_args.add_argument("-gd",
                             "--generate_dots",
                             help="generate a Graphviz dot file for every"
                             "sequential component in a GENDOTS folder.",
                             action="store",
                             dest="gendots",
                             type=str)
    output_args.add_argument("-st",
                             "--steady",
                             help="print steady state probability vector",
                             action="store_true")
    output_args.add_argument("-th",
                             "--performance",
                             help="print throughoutput of actions",
                             action="store_true",
                             dest="top")
    output_args.add_argument("-tr",
                             "--transient",
                             help="print throughoutput of actions",
                             action="store",
                             dest="trantime",
                             type=int)
    # output_args.add_argument("-ut", "--utilization",
    # help="print utilization of action",
    # action="store_true", dest="util")
    output_args.add_argument("-f",
                             "--format",
                             dest="format",
                             type=str,
                             choices=["graph", "console", "csv"],
                             help="format for -st -th -varrate",
                             default="console")
    output_args.add_argument("-o",
                             "--output",
                             dest="output",
                             type=str,
                             action="store",
                             help="output file valid when format cvs")
    exp_args.add_argument("-var",
                          "--variable",
                          help="more or one variables in format"
                          "rate:RATENAME:r:START,STOP,STEP"
                          "or rate:RATENAME:l:val1,val2,val3",
                          action="append",
                          dest="variables")
    exp_args.add_argument("-val", "--value", action="store", dest="yvar")
    exp_args.add_argument("--actionth",
                          help="throughoutput of action on the Y axis",
                          dest="actionth",
                          action="store",
                          metavar="action name")

    args = parser.parse_args()

    logger = init_log(log_level=args.loglevel)
    pargs = {"file": args.file, "solver": args.solver}
    if args.gendots:
        pm = PEPAModel(**pargs)
        import os
        if os.path.isdir(args.gendots):
            pass
        else:
            os.makedirs(args.gendots)
        pm.generate_dots(args.gendots)
        sys.exit(0)

    if args.variables and args.yvar:
        variables = decode_variables(args.variables)
        if len(variables) == 1:
            pm = PEPAModel(**pargs)
            pm.derive()
            result = experiment(variables, args.yvar, pm)
            if args.format == "graph":
                plot_2d(result[0],
                        result[1],
                        lw=2,
                        action="show",
                        xlab=args.yvar,
                        ylab=variables[0].varval)
            elif args.format == "csv":
                with open("{}.csv".format(args.output), "w") as f:
                    for i in range(0, len(result[0])):
                        f.write("{}, {}\n".format(result[0][i], result[1][i]))
        elif len(variables) == 2:
            pm = PEPAModel(**pargs)
            pm.derive()
            result = experiment(variables, args.yvar, pm)
            plot_3d(result[0],
                    result[1],
                    result[2],
                    action="show",
                    xlab=args.yvar,
                    ylab=variables[0].varval)
        else:
            print("Wrong number of -var, either one or two")
            sys.exit(1)

    pm = PEPAModel(**pargs)

    if args.steady or args.top:
        pm.steady_state()
        print("Statespace of {} has {} states \n".format(
            args.file, len(pm.get_steady_state_vector())))
    if args.trantime:
        tr = pm.transient(0, int(args.trantime))
        print("Transient analysis from time %d to %d" % (0, args.trantime))
        args.output = "{}-transient.csv".format(pm.name)
        pretty_print_vector(tr,
                            pm.get_state_names(),
                            fmt=args.format,
                            outfile=args.output)
    if args.steady:
        print("Steady state vector")
        args.output = "{}-steady.csv".format(pm.name)
        pretty_print_vector(pm.get_steady_state_vector(),
                            pm.get_state_names(),
                            fmt=args.format,
                            outfile=args.output)
    if args.top:
        print("Throuhoutput (successful action completion in one time unit)")
        print("Output:{}".format(args.format))
        args.output = "{}-throughput.csv".format(pm.name)
        pretty_print_performance(pm.get_throughoutput(),
                                 fmt=args.format,
                                 outfile=args.output)
Ejemplo n.º 8
0
 def __init__(self):
     self.actionset = []
     self.derivatives = []
     self.log = init_log()
Ejemplo n.º 9
0
 def __init__(self):
     self.max_length = 0
     self.log = init_log()
Ejemplo n.º 10
0
Archivo: cli.py Proyecto: tdi/pyPEPA
def main():
    parser = argparse.ArgumentParser(description="pypepa v{},"
                                     " author {}, {}".format(__version__,
                                     __author__, __email__))
    gen_args = parser.add_argument_group("General", "General arguments")
    gen_args.add_argument("--log", action="store", dest="loglevel", 
                          choices=["DEBUG", "INFO", "ERROR", "NONE"], 
                          help="logging level",
                          default="ERROR", type=str)
    sol_args = parser.add_argument_group("Solution",
                                         "Solution related commands")
    exp_args = parser.add_argument_group("Experimentations",
                                         "Experimentations")

    sol_args.add_argument("-s", "--solver", action="store",
                          dest="solver",type=str,
                          choices=['direct', 'sparse'],
                          help="choose solver type DEFAULT: sparse",
                          default="sparse")
    output_args = parser.add_argument_group("Output", "Output based options")
    parser.add_argument("file", help="path to the model file")
    output_args.add_argument("-gd", "--generate_dots",
                             help="generate a graphviz dot file for every"
                                  "sequential component in a GENDOTS folder and"
                                  "for the whole state space",
                             action="store", dest="gendots", type=str)
    output_args.add_argument("-st", "--steady",
                             help="print steady state probability vector",
                             action="store_true")
    output_args.add_argument("-th", "--performance",
                             help="print throughoutput of actions",
                             action="store_true", dest="top")
    output_args.add_argument("-tr", "--transient",
                             help="print throughoutput of actions",
                             action="store", dest="trantime", type=int)
    # output_args.add_argument("-ut", "--utilization",
                               # help="print utilization of action",
                               # action="store_true", dest="util")
    output_args.add_argument("-f", "--format", dest="format", type=str,
                             choices=["graph", "console", "csv"],
                             help="format for -st -th -varrate", default="console")
    output_args.add_argument("-o", "--output", dest="output", type=str,
                               action="store",
                              help="output file valid when format cvs")
    exp_args.add_argument("-var", "--variable",
                          help="one or more variables in format"
                               "rate:RATENAME:r:START,STOP,STEP"
                               "or rate:RATENAME:l:val1,val2,val3",
                          action="append", dest="variables")
    exp_args.add_argument("-val", "--value", action="store", dest="yvar") 
    # exp_args.add_argument("--actionth",
    #                       help="throughoutput of action on the Y axis",
    #                       dest="actionth", action="store",
    #                       metavar="action name")

    args = parser.parse_args()

    logger = init_log(log_level=args.loglevel)
    pargs = {"file": args.file, "solver" : args.solver}

    if args.gendots:
        try:
            pm = PEPAModel(**pargs)
        except Exception as e:
            print("Exception occured:", e)
            sys.exit(1)
        import os
        if os.path.isdir(args.gendots):
            pass
        else:
            os.makedirs(args.gendots)
        pm.generate_dots(args.gendots)
        sys.exit(0)

    if args.variables and args.yvar:
        variables = decode_variables(args.variables)
        if len(variables) == 1:
            pm = PEPAModel(**pargs)
            pm.derive()
            result = experiment(variables, args.yvar, pm)
            if args.format == "graph":
                plot_2d(result[0], result[1], lw=2, action="show",
                        xlab=args.yvar, ylab=variables[0].varval)
            elif args.format == "csv":
                with open("{}.csv".format(args.output), "w") as f:
                    for i in range(0, len(result[0])):
                            f.write("{}, {}\n".format(result[0][i], result[1][i]))
        elif len(variables) == 2:
            pm = PEPAModel(**pargs)
            pm.derive()
            result = experiment(variables, args.yvar, pm)
            plot_3d(result[0], result[1], result[2], action="show",
                    xlab=args.yvar, ylab=variables[0].varval)
        else:
            print("Wrong number of -var, either one or two")
            sys.exit(1)
    try:
        pm = PEPAModel(**pargs)
    except Exception as e:
        print("Exception occured: ", e)
        sys.exit(1)



    if args.steady or args.top:
        pm.steady_state()
        print("Statespace of {} has {} states \n".format(args.file,
              len(pm.get_steady_state_vector() )))
    if args.trantime:
        tr = pm.transient(0, int(args.trantime))
        print("Transient analysis from time %d to %d" % (0, args.trantime))
        args.output = "{}-transient.csv".format(pm.name)
        pretty_print_vector(tr,
                             pm.get_state_names(),
                             fmt=args.format,
                             outfile=args.output
                             )
    if args.steady:
        print("Steady state vector")
        args.output = "{}-steady.csv".format(pm.name)
        pretty_print_vector(pm.get_steady_state_vector(),
                             pm.get_state_names(),
                             fmt=args.format,
                             outfile=args.output
                             )
    if args.top:
        print("Throuhoutput (successful action completion in one time unit)")
        print("Output:{}".format(args.format))
        args.output = "{}-throughput.csv".format(pm.name)
        pretty_print_performance(pm.get_throughoutput(), fmt=args.format,
                                                         outfile=args.output)