예제 #1
0
def _example_data(simulation_name):
    from sirepo import simulation_db
    from sirepo.template import elegant
    for data in simulation_db.examples(elegant.SIM_TYPE):
        if data.models.simulation.name == simulation_name:
            return simulation_db.fixup_old_data(data)[0]
    assert False
예제 #2
0
def _example_data(simulation_name):
    from sirepo import simulation_db
    from sirepo.template import elegant
    for data in simulation_db.examples(elegant.SIM_TYPE):
        if data.models.simulation.name == simulation_name:
            return simulation_db.fixup_old_data(data)[0]
    raise AssertionError(f'failed to find example={simulation_name}')
예제 #3
0
def _example_data(simulation_name):
    from sirepo import simulation_db
    from sirepo.template import shadow
    for data in simulation_db.examples(shadow.SIM_TYPE):
        if data.models.simulation.name == simulation_name:
            return simulation_db.fixup_old_data(data)[0]
    assert False
예제 #4
0
def _example_data(name):
    from sirepo import simulation_db
    from sirepo.template import synergia

    for d in simulation_db.examples(synergia.SIM_TYPE):
        if d.models.simulation.name == name:
            return simulation_db.fixup_old_data(d)[0]
    assert False
예제 #5
0
def api_saveSimulationData():
    # do not fixup_old_data yet
    req = http_request.parse_post(id=True, template=True)
    d = req.req_data
    simulation_db.validate_serial(d)
    d = simulation_db.fixup_old_data(d)[0]
    if hasattr(req.template, 'prepare_for_save'):
        d = req.template.prepare_for_save(d)
    d = simulation_db.save_simulation_json(d)
    return api_simulationData(
        d.simulationType,
        d.models.simulation.simulationId,
    )
예제 #6
0
def _start_simulation(data, run_async=False):
    """Setup and start the simulation.

    Args:
        data (dict): app data
        run_async (bool): run-background or run

    Returns:
        object: _Command or daemon instance
    """
    run_dir = simulation_db.simulation_run_dir(data, remove_dir=True)
    pkio.mkdir_parent(run_dir)
    #TODO(robnagler) create a lock_dir -- what node/pid/thread to use?
    #   probably can only do with celery.
    simulation_type = data['simulationType']
    sid = simulation_db.parse_sid(data)
    data = simulation_db.fixup_old_data(simulation_type, data)
    assert simulation_type in simulation_db.APP_NAMES, \
        '{}: invalid simulation type'.format(simulation_type)
    template = sirepo.template.import_module(simulation_type)
    for d in simulation_db.simulation_dir(
            simulation_type,
            sid), simulation_db.simulation_lib_dir(simulation_type):
        for f in glob.glob(str(d.join('*.*'))):
            if os.path.isfile(f):
                py.path.local(f).copy(run_dir)
    template.prepare_aux_files(run_dir, data)
    simulation_db.save_simulation_json(simulation_type, data)
    with open(str(run_dir.join('in{}'.format(simulation_db.JSON_SUFFIX))),
              'w') as outfile:
        json.dump(data, outfile)
    pkio.write_text(
        run_dir.join(simulation_type + '_parameters.py'),
        template.generate_parameters_file(
            data,
            _schema_cache(simulation_type),
            run_dir=run_dir,
            run_async=run_async,
        ))

    cmd = [_ROOT_CMD, simulation_type] \
        + ['run-background' if run_async else 'run'] + [str(run_dir)]
    if run_async:
        return cfg.job_queue(sid, run_dir, cmd)
    return _Command(cmd, cfg.foreground_time_limit)
예제 #7
0
def _start_simulation(data, run_async=False):
    """Setup and start the simulation.

    Args:
        data (dict): app data
        run_async (bool): run-background or run

    Returns:
        object: _Command or daemon instance
    """
    run_dir = simulation_db.simulation_run_dir(data, remove_dir=True)
    pkio.mkdir_parent(run_dir)
    #TODO(robnagler) create a lock_dir -- what node/pid/thread to use?
    #   probably can only do with celery.
    simulation_type = data['simulationType']
    sid = simulation_db.parse_sid(data)
    data = simulation_db.fixup_old_data(simulation_type, data)
    assert simulation_type in simulation_db.APP_NAMES, \
        '{}: invalid simulation type'.format(simulation_type)
    template = sirepo.template.import_module(simulation_type)
    simulation_db.save_simulation_json(simulation_type, data)
    for d in simulation_db.simulation_dir(simulation_type, sid), simulation_db.simulation_lib_dir(simulation_type):
        for f in glob.glob(str(d.join('*.*'))):
            if os.path.isfile(f):
                py.path.local(f).copy(run_dir)
    with open(str(run_dir.join('in{}'.format(simulation_db.JSON_SUFFIX))), 'w') as outfile:
        json.dump(data, outfile)
    pkio.write_text(
        run_dir.join(simulation_type + '_parameters.py'),
        template.generate_parameters_file(
            data,
            _schema_cache(simulation_type),
            run_dir=run_dir,
            run_async=run_async,
        )
    )

    cmd = [_ROOT_CMD, simulation_type] \
        + ['run-background' if run_async else 'run'] + [str(run_dir)]
    if run_async:
        return cfg.job_queue(sid, run_dir, cmd)
    return _Command(cmd, cfg.foreground_time_limit)
예제 #8
0
파일: importer.py 프로젝트: JiayangY/sirepo
def read_json(text, sim_type=None):
    """Read json file and return

    Args:
        text (IO): file to be read
        sim_type (str): expected type

    Returns:
        dict: data
    """
    from sirepo import simulation_db

    # attempt to decode the input as json first, if invalid try python
    # fixup data in case new structures are need for lib_file ops below
    data = simulation_db.fixup_old_data(simulation_db.json_load(text))[0]
    assert not sim_type or data.simulationType == sim_type, \
        'simulationType={} invalid, expecting={}'.format(
            data.simulationType,
            sim_type,
        )
    return sirepo.http_request.parse_post(req_data=data).req_data
예제 #9
0
파일: importer.py 프로젝트: e-carlin/sirepo
def read_json(text, template=None):
    """Read json file and return

    Args:
        text (IO): file to be read
        template (module): expected type

    Returns:
        dict: data
    """
    from sirepo import simulation_db

    # attempt to decode the input as json first, if invalid try python
    # fixup data in case new structures are need for lib_files() below
    data = simulation_db.fixup_old_data(simulation_db.json_load(text))[0]
    if template:
        assert data.simulationType == template.SIM_TYPE, \
            'simulationType {} invalid, expecting {}'.format(
                data.simulationType,
                template.SIM_TYPE,
            )
    return data
예제 #10
0
파일: importer.py 프로젝트: yeeon/sirepo
def read_json(text, template=None):
    """Read json file and return

    Args:
        text (IO): file to be read
        template (module): expected type

    Returns:
        dict: data
    """
    from sirepo import simulation_db

    # attempt to decode the input as json first, if invalid try python
    # fixup data in case new structures are need for lib_files() below
    data = simulation_db.fixup_old_data(simulation_db.json_load(text))[0]
    if template:
        assert data.simulationType == template.SIM_TYPE, \
            'simulationType {} invalid, expecting {}'.format(
                data.simulationType,
                template.SIM_TYPE,
            )
    return data
예제 #11
0
파일: server.py 프로젝트: mrakitin/sirepo
def _parse_data_input(validate=False):
    data = _json_input()
    return simulation_db.fixup_old_data(data)[0] if validate else data
예제 #12
0
파일: server.py 프로젝트: yeeon/sirepo
def _parse_data_input(validate=False):
    data = http_request.parse_json(assert_sim_type=False)
    return simulation_db.fixup_old_data(data)[0] if validate else data
예제 #13
0
def _find_example(name):
    from sirepo import simulation_db
    for ex in simulation_db.examples(_elegant().SIM_TYPE):
        if ex.models.simulation.name == name:
            return simulation_db.fixup_old_data(ex)[0]
    assert False, 'no example named: {}'.format(name)
예제 #14
0
def _parse_data_input(validate=False):
    data = _json_input()
    return simulation_db.fixup_old_data(data)[0] if validate else data