def setUp(self):
        linac = Linac()

        linac.add_beamline(
            'astra',
            name='gun',
            swd=osp.join(test_path, 'astra'),
            fin='injector.in',
            template=osp.join(test_path, 'astra/injector.in.000'),
            pout='injector.0100.001')

        linac.add_beamline(
            'impactt',
            name='matching',
            swd=osp.join(test_path, 'impactt'),
            fin='ImpactT.in',
            template=osp.join(test_path, 'impactt/ImpactT.in.000'),
            pout='fort.106',
            charge=10e-12)

        self.opt = LinacOptimization(linac)

        self.opt.add_obj('f', expr='matching.out.emitx', scale=1e6)

        self.opt.add_icon('g1', func=lambda a: a.gun.out.Sx * 1e3, ub=0.2)
        self.opt.add_icon('g2', func=lambda a: a.matching.out.betax, ub=0.2)
        self.opt.add_icon('g3', func=lambda a: a.matching.out.betay, ub=0.2)
        self.opt.add_icon(
            'g4',
            func=lambda a: abs(a.matching.out.betax - a.matching.out.betay),
            ub=0.01)

        self.opt.add_var('gun/laser_spot', value=0.1, lb=0.04, ub=0.30)
        self.opt.add_var('matching/MQZM1_G', value=0.0, lb=-6.0, ub=0.0)
        self.opt.add_var('matching/MQZM2_G', value=0.0, lb=0.0, ub=6.0)
Exemple #2
0
    def setUp(self):
        linac = Linac()
        linac.add_beamline('astra',
                           name='gun',
                           swd=test_path,
                           fin='injector.in',
                           template=osp.join(test_path, 'injector.in.000'),
                           pout='injector.0150.001')

        self.opt = LinacOptimization(linac)
        # self.opt.printout = 1

        self.opt.add_obj('emitx_um', expr='gun.out.emitx', scale=1.e6)
        self.opt.add_var('laser_spot', value=0.1, lb=0.04, ub=0.3)
        self.opt.add_var('main_sole_b', value=0.1, lb=0.0, ub=0.4)
    def setUp(self):
        linac = Linac()
        linac.add_beamline('astra',
                           name='gun',
                           swd=test_path,
                           fin='injector.in',
                           template=osp.join(test_path, 'injector.in.000'),
                           pout='injector.0150.001')

        self.opt = LinacOptimization(linac)

        self.opt.add_obj('f', expr='gun.out.Sx', scale=1.e6)
        self.opt.add_icon('g1',
                          func=lambda a: a['gun'].max.emitx * 1e6,
                          ub=0.041)
        self.opt.add_econ('g2', func=lambda a: a['gun'].out.gamma, eq=10.0)

        self.opt.add_var('laser_spot', value=0.1, lb=0.04, ub=0.3)
        self.opt.add_var('main_sole_b', value=0.1, lb=0.0, ub=0.3)
        self.opt.add_var('gun_gradient', value=130, lb=90.0, ub=130.0)
Exemple #4
0
# fin: simulation input file name
# template: simulation input template file path.
# pout: output file name. It must be in the same folder as 'fin'.
linac.add_beamline('astra',
                   name='gun',
                   swd='../astra_files',
                   fin='injector.in',
                   template='injector.in.000',
                   pout='injector.0450.001')

mapping = {
    'laser_spot': 0.1,
    'main_sole_b': 0.2,
}

opt = LinacOptimization(linac)  # instantiate Optimization (problem)

# There are two options to access a parameter of a linac:
# 1. Use a string: the string must have the form
#        beamline_name.WatchParameters_name.param_name
#    or
#        beamline_name.LineParameters_name.param_name.
# 2. Use a function object: the function has only one argument which is
#    the linac instance.

# add the objective (the horizontal emittance at the end of the 'gun' beamline)
opt.add_obj('emitx_um', expr='gun.out.emitx', scale=1e6)

# add variables with lower boundary (lb) and upper boundary (ub)
opt.add_var('laser_spot', value=0.10, lb=0.04, ub=0.3)
opt.add_var('main_sole_b', value=0.20, lb=0.00, ub=0.4)
                   template='injector.in.000',
                   pout='injector.0450.001')

# Add the second beamline
#
# Note: 'charge' is required for an ImpactT simulation but this argument
# will be ignored if the code is Astra.
linac.add_beamline('impactt',
                   name='chicane',
                   swd='../impactt_files',
                   fin='ImpactT.in',
                   template='ImpactT.in.000',
                   pout='fort.106',
                   charge=1e-15)

opt = LinacOptimization(linac)

opt.add_obj('St_betaxy',
            func=lambda a: max(a['chicane'].out.emitx * 1e6, a['chicane'].out.
                               betax, a['chicane'].out.betay))

opt.add_var('gun/laser_spot', value=0.1, lb=0.04, ub=0.30)
opt.add_var('gun/main_sole_b', value=0.1, lb=0.00, ub=0.40)
opt.add_var('chicane/MQZM1_G', value=0.0, lb=-10, ub=10)
opt.add_var('chicane/MQZM3_G', value=0.0, lb=-10, ub=10)

opt.add_covar('chicane/MQZM2_G', 'chicane/MQZM1_G', scale=-1)
opt.add_covar('chicane/MQZM4_G', 'chicane/MQZM3_G', scale=-1)

optimizer = NelderMead()
opt.solve(optimizer)