Пример #1
0
    def get_class(cls, *args, **kwargs):
        """ Returns subclass .

        """
        parser = EntryPoint(cls.get_class_parameters(), strict=True)
        opt = parser.parse(*args, **kwargs)
        return cls._get_class(opt)
Пример #2
0
    def __init__(self, *args, **kwargs):
        # for reasons of import-order and class creation, decoration was not possible
        parser = EntryPoint(self.get_instance_parameters(), strict=True)
        opt = parser.parse(*args, **kwargs)

        # required
        self.nat_tune_x = opt.nat_tune_x
        self.nat_tune_y = opt.nat_tune_y
        self.acd = opt.acd
        if self.acd:
            self.drv_tune_x = opt.drv_tune_x
            self.drv_tune_y = opt.drv_tune_y

        # optional with default
        self.fullresponse = opt.fullresponse

        # optional w/o default
        self.energy = opt.get("energy", None)

        self.year_opt = opt.year_opt
        if self.year_opt is None:
            self.year_opt = CURRENT_YEAR

        self.dpp = opt.get("dpp", 0.0)
        
        self.optics_file = opt.get("optics", None)
Пример #3
0
    def __init__(self, *args, **kwargs):
        # for reasons of import-order and class creation, decoration was not possible
        parser = EntryPoint(self.get_instance_parameters(), strict=True)
        opt = parser.parse(*args, **kwargs)

        # required
        self.nat_tune_x = opt.nat_tune_x
        self.nat_tune_y = opt.nat_tune_y
        self.acd = opt.acd
        if self.acd:
            self.drv_tune_x = opt.drv_tune_x
            self.drv_tune_y = opt.drv_tune_y

        # optional with default
        self.fullresponse = opt.fullresponse

        # optional w/o default
        self.energy = opt.get("energy", None)

        Ps.YEAR = opt.year_opt
        if Ps.YEAR is None:
            Ps.YEAR = CURRENT_YEAR

        self.dpp = opt.get("dpp", 0.0)
        
        self.optics_file = opt.get("optics", None)
Пример #4
0
    def get_class_and_unknown(cls, *args, **kwargs):
        """ Returns Psbooster subclass and unkown args .

        For the desired philosophy of returning parameters all the time,
        try to avoid this function, e.g. parse outside parameters first.
        """
        parser = EntryPoint(cls.get_class_parameters(), strict=False)
        opt, unknown_opt = parser.parse(*args, **kwargs)
        return cls._get_class(opt), unknown_opt
Пример #5
0
    def get_class_and_unknown(cls, *args, **kwargs):
        """ Returns Psbooster subclass and unkown args .

        For the desired philosophy of returning parameters all the time,
        try to avoid this function, e.g. parse outside parameters first.
        """
        parser = EntryPoint(cls.get_class_parameters(), strict=False)
        opt, unknown_opt = parser.parse(*args, **kwargs)
        return cls._get_class(opt), unknown_opt
Пример #6
0
def get_accel_class_from_args(args=None):
    """ LEGACY-FUNCTION SHOULD BE REPLACED BY USING get_accel_class """
    parser = EntryPoint(_get_params())
    opt, class_args = parser.parse(args)

    accel = _get_parent_class(opt.accel)

    accel_args, rest_args = split_arguments(class_args, accel.get_class_parameters())
    accel_cls = accel.get_class(accel_args)
    return accel_cls, rest_args
Пример #7
0
def get_accel_class_from_args(args=None):
    """ LEGACY-FUNCTION SHOULD BE REPLACED BY USING get_accel_class """
    parser = EntryPoint(_get_params())
    opt, class_args = parser.parse(args)

    accel = _get_parent_class(opt.accel)

    accel_args, rest_args = split_arguments(class_args, accel.get_class_parameters())
    accel_cls = accel.get_class(accel_args)
    return accel_cls, rest_args
Пример #8
0
    def get_class(cls, *args, **kwargs):
        """ Returns Ps class.

        Keyword Args:

        Returns:
            Ps class.
        """
        parser = EntryPoint(cls.get_class_parameters(), strict=True)
        opt = parser.parse(*args, **kwargs)
        return cls._get_class(opt)
Пример #9
0
    def get_class(cls, *args, **kwargs):
        """ Returns Psbooster class.

        Keyword Args:
            Optional
            ring (int): Ring to use.
                        **Flags**: ['--ring']
                        **Choices**: [1, 2, 3, 4]

        Returns:
            Psbooster class.
        """
        parser = EntryPoint(cls.get_class_parameters(), strict=True)
        opt = parser.parse(*args, **kwargs)
        return cls._get_class(opt)
Пример #10
0
    def get_class(cls, *args, **kwargs):
        """ Returns Psbooster class.

        Keyword Args:
            Optional
            ring (int): Ring to use.
                        **Flags**: ['--ring']
                        **Choices**: [1, 2, 3, 4]

        Returns:
            Psbooster class.
        """
        parser = EntryPoint(cls.get_class_parameters(), strict=True)
        opt = parser.parse(*args, **kwargs)
        return cls._get_class(opt)
Пример #11
0
    def get_class(cls, *args, **kwargs):
        """ Returns LHC subclass .

        Keyword Args:
            Optional
            beam (int): Beam to use.
                        **Flags**: ['--beam']
            lhc_mode (str): LHC mode to use.
                            **Flags**: ['--lhcmode']
                            **Choices**: ['lhc_runII_2016_ats', 'hllhc12', 'hllhc10', 'lhc_runI',
                            'lhc_runII', 'lhc_runII_2016', 'lhc_runII_2017']

        Returns:
            Lhc subclass.
        """
        parser = EntryPoint(cls.get_class_parameters(), strict=True)
        opt = parser.parse(*args, **kwargs)
        return cls._get_class(opt)
Пример #12
0
    def get_class(cls, *args, **kwargs):
        """ Returns LHC subclass .

        Keyword Args:
            Optional
            beam (int): Beam to use.
                        **Flags**: ['--beam']
            lhc_mode (str): LHC mode to use.
                            **Flags**: ['--lhcmode']
                            **Choices**: ['lhc_runII_2016_ats', 'hllhc12', 'hllhc10', 'lhc_runI',
                            'lhc_runII', 'lhc_runII_2016', 'lhc_runII_2017']

        Returns:
            Lhc subclass.
        """
        parser = EntryPoint(cls.get_class_parameters(), strict=True)
        opt = parser.parse(*args, **kwargs)
        return cls._get_class(opt)
Пример #13
0
    def __init__(self, *args, **kwargs):
        # for reasons of import-order and class creation, decoration was not possible
        parser = EntryPoint(self.get_instance_parameters(), strict=True)
        opt = parser.parse(*args, **kwargs)

        if opt.model_dir:
            self.init_from_model_dir(opt.model_dir)
            self.energy = None
            if opt.nat_tune_x is not None:
                raise AcceleratorDefinitionError("Argument 'nat_tune_x' not allowed when loading from model directory.")
            if opt.nat_tune_y is not None:
                raise AcceleratorDefinitionError("Argument 'nat_tune_y' not allowed when loading from model directory.")
        else:
            if opt.nat_tune_x is None:
                raise AcceleratorDefinitionError("Argument 'nat_tune_x' is required.")
            if opt.nat_tune_y is None:
                raise AcceleratorDefinitionError("Argument 'nat_tune_y' is required.")

            self.nat_tune_x = opt.nat_tune_x
            self.nat_tune_y = opt.nat_tune_y

            # optional with default
            self.dpp = opt.dpp
            self.fullresponse = opt.fullresponse

            # optional no default
            self.energy = opt.get("energy", None)
            self.xing = opt.get("xing", None)
            self.optics_file = opt.get("optics", None)

            # for GetLLM
            self.model_dir = None
            self._model = None
            self._model_best_knowledge = None
            self._elements = None
            self._elements_centre = None
            self._errordefspath = None

        self.verify_object()
Пример #14
0
    def __init__(self, *args, **kwargs):
        # for reasons of import-order and class creation, decoration was not possible
        parser = EntryPoint(self.get_instance_parameters(), strict=True)
        opt = parser.parse(*args, **kwargs)

        if opt.model_dir:
            self.init_from_model_dir(opt.model_dir)
            self.energy = None
            self.dpp = 0.0
            self.xing = None
            if opt.nat_tune_x is not None:
                raise AcceleratorDefinitionError(
                    "Argument 'nat_tune_x' not allowed when loading from model directory."
                )
            if opt.nat_tune_y is not None:
                raise AcceleratorDefinitionError(
                    "Argument 'nat_tune_y' not allowed when loading from model directory."
                )
            if opt.drv_tune_x is not None:
                raise AcceleratorDefinitionError(
                    "Argument 'drv_tune_x' not allowed when loading from model directory."
                )
            if opt.drv_tune_y is not None:
                raise AcceleratorDefinitionError(
                    "Argument 'drv_tune_y' not allowed when loading from model directory."
                )
        else:
            if opt.nat_tune_x is None:
                raise AcceleratorDefinitionError(
                    "Argument 'nat_tune_x' is required.")
            if opt.nat_tune_y is None:
                raise AcceleratorDefinitionError(
                    "Argument 'nat_tune_y' is required.")

            self.nat_tune_x = opt.nat_tune_x
            self.nat_tune_y = opt.nat_tune_y

            self.drv_tune_x = None
            self.drv_tune_y = None
            self._excitation = AccExcitationMode.FREE

            if opt.acd or opt.adt:
                if opt.acd and opt.adt:
                    raise AcceleratorDefinitionError(
                        "Select only one excitation type.")

                if opt.drv_tune_x is None:
                    raise AcceleratorDefinitionError(
                        "Argument 'drv_tune_x' is required.")
                if opt.drv_tune_y is None:
                    raise AcceleratorDefinitionError(
                        "Argument 'drv_tune_x' is required.")
                self.drv_tune_x = opt.drv_tune_x
                self.drv_tune_y = opt.drv_tune_y

                if opt.acd:
                    self._excitation = AccExcitationMode.ACD
                elif opt.adt:
                    self._excitation = AccExcitationMode.ADT

            # optional with default
            self.dpp = opt.dpp
            self.fullresponse = opt.fullresponse

            # optional no default
            self.energy = opt.get("energy", None)
            self.xing = opt.get("xing", None)
            self.optics_file = opt.get("optics", None)

            # for GetLLM
            self.model_dir = None
            self._model = None
            self._model_driven = None
            self._model_best_knowledge = None
            self._elements = None
            self._elements_centre = None
            self._errordefspath = None

        self.verify_object()
def as_parser_test():
    kw_dict = dict(accel="LHCB5", anumber=5.6, anint=10, alist=[1, 2, 3])
    p = EntryPoint(_get_params_list())
    opt, uopt = p.parse(**kw_dict)
    print_dict_tree(opt)
Пример #16
0
def as_parser_test():
    kw_dict = dict(accel="LHCB5", anumber=5.6, anint=10, alist=[1, 2, 3])
    p = EntryPoint(_get_params_list())
    opt, uopt = p.parse(**kw_dict)
    print_dict_tree(opt)