Пример #1
0
def sim(what, *devices, **kwargs):
    """Run code or a script file in dry run mode.

    If the file name is not absolute, it is relative to the experiment script
    directory.

    For script files, position statistics will be collected for the given list
    of devices:

    >>> sim('testscript', T)

    will simulate the 'testscript.py' user script.

    Dry run mode does a non-physical emulation by running all the instrument
    specific code with virtualized devices.  Any problems which would appear
    runnig the same commands in 'master' mode (with ideal hardware) can be
    spotted by the user, such as devices moving out of limits, failing
    calculations, or invalid parameters.

    Furthermore, the ranges of all devices which are moved are recorded and
    the required time to run a command or script is estimated from device
    properties ('speed', 'ramp', 'accel').

    Example with running code directly:

    >>> sim('move(mono, 1.55); read(mtt)')
    """
    debug = bool(kwargs.get('debug', False))
    fn = _scriptfilename(what)
    if not path.isfile(fn) and not what.endswith(('.py', '.txt')):
        try:
            compile(what + '\n', 'exec', 'exec')
        except Exception:
            raise NicosError('Argument is neither a script file nor valid '
                             'code')
        session.runSimulation('_RunCode(%r, %s)' % (what, debug))
        return
    if session.mode == SIMULATION:
        return _RunScript(what, devices)
    session.runSimulation('_RunScript(%r, [%s], %s)' %
                          (what, ', '.join(dev.name for dev in devices),
                           debug))
Пример #2
0
 def simulate_request(self, request, quiet=False):
     code, _ = parseScript(request.text, request.name, compilecode=False)
     session.runSimulation(code[0], request.reqid, wait=False, quiet=quiet)