Esempio n. 1
0
    def main(cls, argv=None):
        """
        Create an application instance and run the MainLoop.

        :param list argv: command line parameters
        """
        from docopt import docopt
        args = docopt(cls.usage, argv, version=cls.version)
        conf = load_config(args['--config'])
        cls(args, conf).MainLoop()
Esempio n. 2
0
def session(app):
    config = load_config(isolated=True)
    session = Session(config)
    session.control._settings.update({
        'shot_interval': 0.001,
        'jitter': True,
        'auto_params': True,
        'auto_sd': True,
    })
    return session
Esempio n. 3
0
def session(app):
    config = load_config(isolated=True)
    session = Session(config)
    session.control._settings.update({
        'shot_interval': 0.001,
        'jitter': True,
        'auto_params': True,
        'auto_sd': True,
    })
    return session
Esempio n. 4
0
    def session(cls, model_file, record_files):
        from madgui.core.session import Session
        from madgui.core.config import load as load_config
        from glob import glob
        if isinstance(record_files, str):
            record_files = glob(record_files, recursive=True)

        config = load_config(isolated=True)
        session = Session(config)
        session.load_model(model_file, stdout=False, undo_stack=UndoStack())
        model = session.model()
        measured = OrbitResponse.load(model, record_files)
        analysis = cls(model, measured)
        analysis.session = session
        return analysis
Esempio n. 5
0
 def __init__(self, config=None):
     if config is None:
         config = load_config()
     self.config = config
     self.window = Boxed(None)
     self.model = Boxed(None)
     self.control = Control(self)
     self.matcher = None
     self.user_ns = user_ns = SimpleNamespace()
     self.session_file = userpath(config.session_file)
     self.folder = userpath(config.model_path)
     self.selected_elements = Selection()
     self.model.changed2.connect(self.on_model_changed)
     # Maintain these members into the namespace
     subscribe(user_ns, 'model', self.model)
     subscribe(user_ns, 'window', self.window)
     user_ns.config = config
     user_ns.context = self
     user_ns.control = self.control
Esempio n. 6
0
 def __init__(self, config=None):
     if config is None:
         config = load_config()
     self.config = config
     self.window = Boxed(None)
     self.model = Boxed(None)
     self.control = Control(self)
     self.matcher = None
     self.user_ns = user_ns = SimpleNamespace()
     self.session_file = userpath(config.session_file)
     self.folder = userpath(config.model_path)
     self.selected_elements = Selection()
     self.model.changed2.connect(self.on_model_changed)
     # Maintain these members into the namespace
     subscribe(user_ns, 'model', self.model)
     subscribe(user_ns, 'window', self.window)
     user_ns.config = config
     user_ns.context = self
     user_ns.control = self.control
Esempio n. 7
0
def main(args=None):
    opts = docopt(__doc__, args)
    model_path = opts['--model'] or '../hit_models/hht3'

    init_app(['madgui'])

    blacklist = opts['--blacklist'] or [
        's4mu1e', 's4mu2e',
        's3me2e', 's3mu1a', 's3ms1v',
        's0qg4d', 's0qg1f',
    ]

    def blacklisted(name):
        return name in blacklist or any(b in name for b in blacklist)

    config = load_config(isolated=True)
    session = Session(config)
    session.load_model(model_path, stdout=False)
    model = session.model()

    by_type = get_elements_by_type(model)

    if opts['--twiss']:
        print('')
        print('############')
        print('## TWISS  ##')
        print('############')
        print('\n'.join(get_twiss_args_errors()))

    if opts['--ealign']:
        print('')
        print('############')
        print('## EALIGN ##')
        print('############')
        for base_name in sorted(by_type):
            print('')
            print('# {}'.format(base_name))
            for elem in by_type[base_name]:
                if not blacklisted(elem):
                    print('\n'.join(get_ealign_errors(elem)))

    if opts['--knobs']:
        print('')
        print('############')
        print('## KNOBS  ##')
        print('############')

        for base_name in sorted(by_type):
            print('')
            print('# {}'.format(base_name))
            for elem in by_type[base_name]:
                if not blacklisted(elem):
                    print('\n'.join(get_knob_errors(model, elem)))

    if opts['--attr']:
        print('')
        print('############')
        print('## ATTRS  ##')
        print('############')
        for spec in opts['--attr']:
            type_, attrs = spec.split('->', 1)
            attrs = attrs.split('/')
            for elem in model.elements:
                if elem.base_name == type_:
                    print('\n'.join(
                        '{}->{}'.format(elem.name, attr) for attr in attrs))
Esempio n. 8
0
def main(model_file, spec_file, record_file):
    """
    Usage:
        analysis MODEL PARAMS RECORDS

    MODEL must be the path of the model/sequence file to initialize MAD-X.

    PARAMS is a YAML file with arguments for the "measurement" procedure, it
        must contain at least a list of `monitors` and `optics` and should
        contain keys for errors to be inserted: `knobs`, `ealign`, `efcomp`

    RECORDS is the name of the YAML output file where
    """
    init_app([], gui=False)

    config = load_config(isolated=True)
    with ExitStack() as stack:
        setup_args = yaml.load_file(spec_file)['procedure']
        session = stack.enter_context(Session(config))
        session.control._settings.update({
            'shot_interval':
            0.001,
            'jitter':
            setup_args.get('jitter', True),
            'auto_params':
            False,
            'auto_sd':
            True,
        })
        session.load_model(model_file,
                           stdout=False,
                           command_log=lambda text: print("X:>", text))
        session.control.set_backend('hit_acs.plugin:TestACS')
        session.control.connect()
        session.control.write_all()
        corrector = Corrector(session)
        corrector.setup({
            'monitors': setup_args['monitors'],
            'optics': setup_args['optics'],
        })

        # FIXME: this is not yet compatible with general parameter errors. In
        # order to fix this, the hit_acs test backend will have to use an
        # independent model!
        model = session.model()
        import_errors(model, setup_args['errors'])
        model.twiss.invalidate()

        corrector.set_optics_delta(setup_args.get('optics_deltas', {}),
                                   setup_args.get('default_delta', 1e-4))
        corrector.open_export(record_file)

        widget = mock.Mock()
        procbot = ProcBot(widget, corrector)

        num_mons = len(setup_args['monitors'])
        num_optics = len(setup_args['optics']) + 1
        if setup_args.get('jitter', True):
            num_ignore = setup_args.get('num_ignore', 1)
            num_shots = setup_args.get('num_shots', 5)
        else:
            num_ignore = 0
            num_shots = 1

        procbot.start(num_ignore, num_shots, gui=False)

        total_steps = num_mons * (num_optics + 1) * (num_ignore + num_shots)

        i = 0
        while procbot.running and i < 2 * total_steps:
            procbot._feed(None, None)
            time.sleep(0.010)
            i += 1

        assert not procbot.running