def __init__(self):
        self._compute = list()
        self._scheduled = False
        self._updaters = SyncedList(OnlyType(Updater),
                                    _triggered_op_conversion)
        self._writers = SyncedList(OnlyType(Writer), _triggered_op_conversion)
        self._tuners = SyncedList(OnlyType(Tuner), lambda x: x._cpp_obj)
        self._computes = SyncedList(OnlyType(Compute), lambda x: x._cpp_obj)
        self._integrator = None

        self._tuners.append(ParticleSorter())
Exemple #2
0
    def __init__(self, filter, limit=None):

        # store metadata
        param_dict = ParameterDict(
            filter=ParticleFilter,
            limit=OnlyType(float, allow_none=True),
            zero_force=OnlyType(bool, allow_none=False),
        )
        param_dict.update(dict(filter=filter, limit=limit, zero_force=False))

        # set defaults
        self._param_dict.update(param_dict)
Exemple #3
0
 def __init__(self, box1, box2, variant, trigger, scale_particles=True):
     params = ParameterDict(box1=OnlyType(Box,
                                          preprocess=box_preprocessing),
                            box2=OnlyType(Box,
                                          preprocess=box_preprocessing),
                            variant=Variant,
                            scale_particles=bool)
     params['box1'] = box1
     params['box2'] = box2
     params['variant'] = variant
     params['trigger'] = trigger
     params['scale_particles'] = scale_particles
     self._param_dict.update(params)
     super().__init__(trigger)
Exemple #4
0
    def __init__(self, filter, seed, rotation_diff=0.1):
        # store metadata
        param_dict = ParameterDict(
            filter=ParticleFilter,
            seed=int(seed),
            rotation_diff=float(rotation_diff),
            constraint=OnlyType(ConstraintForce,
                                allow_none=True,
                                preprocess=ellip_preprocessing),
        )
        param_dict.update(
            dict(constraint=None,
                 rotation_diff=rotation_diff,
                 seed=seed,
                 filter=filter))
        # set defaults
        self._param_dict.update(param_dict)

        active_force = TypeParameter('active_force',
                                     type_kind='particle_types',
                                     param_dict=TypeParameterDict((1, 0, 0),
                                                                  len_keys=1))
        active_torque = TypeParameter('active_torque',
                                      type_kind='particle_types',
                                      param_dict=TypeParameterDict((0, 0, 0),
                                                                   len_keys=1))

        self._extend_typeparam([active_force, active_torque])
Exemple #5
0
    def __init__(self,
                 filter,
                 kT,
                 seed,
                 alpha=None,
                 tally_reservoir_energy=False):

        # store metadata
        param_dict = ParameterDict(
            filter=ParticleFilter,
            kT=Variant,
            seed=int(seed),
            alpha=OnlyType(float, allow_none=True),
            tally_reservoir_energy=bool(tally_reservoir_energy),
        )
        param_dict.update(dict(kT=kT, alpha=alpha, filter=filter))
        # set defaults
        self._param_dict.update(param_dict)

        gamma = TypeParameter('gamma',
                              type_kind='particle_types',
                              param_dict=TypeParameterDict(1., len_keys=1))

        gamma_r = TypeParameter('gamma_r',
                                type_kind='particle_types',
                                param_dict=TypeParameterDict((1., 1., 1.),
                                                             len_keys=1))

        self._extend_typeparam([gamma, gamma_r])
Exemple #6
0
    def __init__(self,
                 logger,
                 output=stdout,
                 header_sep='.',
                 delimiter=' ',
                 pretty=True,
                 max_precision=10,
                 max_header_len=None):
        def writable(fh):
            if not fh.writable():
                raise ValueError("file-like object must be writable.")
            return fh

        param_dict = ParameterDict(header_sep=str,
                                   delimiter=str,
                                   min_column_width=int,
                                   max_header_len=OnlyType(int,
                                                           allow_none=True),
                                   pretty=bool,
                                   max_precision=int,
                                   output=OnlyType(_OutputWriter,
                                                   postprocess=writable),
                                   logger=Logger)

        param_dict.update(
            dict(header_sep=header_sep,
                 delimiter=delimiter,
                 min_column_width=max(10, max_precision + 6),
                 max_header_len=max_header_len,
                 max_precision=max_precision,
                 pretty=pretty,
                 output=output,
                 logger=logger))
        self._param_dict = param_dict

        # internal variables that are not part of the state.
        # Ensure that only scalar and potentially string are set for the logger
        if (LoggerCategories.scalar not in logger.categories
                or logger.categories & self._invalid_logger_categories !=
                LoggerCategories.NONE):
            raise ValueError(
                "Given Logger must have the scalar categories set.")

        self._cur_headers_with_width = dict()
        self._fmt = _Formatter(pretty, max_precision)
        self._comm = None
Exemple #7
0
 def __init__(self, trigger=200, grid=None):
     self._param_dict = ParameterDict(
         trigger=Trigger,
         grid=OnlyType(
             int,
             postprocess=lambda x: int(ParticleSorter._to_power_of_two(x)),
             preprocess=ParticleSorter._natural_number,
             allow_none=True))
     self.trigger = trigger
     self.grid = grid
Exemple #8
0
 def __init__(self, nlist, r_cut=None, mode="none"):
     self._nlist = OnlyType(md.nlist.NList, strict=True)(nlist)
     tp_r_cut = TypeParameter('r_cut', 'particle_types',
                              TypeParameterDict(positive_real, len_keys=2)
                              )
     if r_cut is not None:
         tp_r_cut.default = r_cut
     self._param_dict.update(
         ParameterDict(mode=OnlyFrom(['none', 'shift'])))
     self.mode = mode
     self._add_typeparam(tp_r_cut)
    def __init__(self, moves, target, solver, types=None,
                 max_translation_move=None, max_rotation_move=None):
        def target_postprocess(target):
            def check_fraction(value):
                if 0 <= value <= 1:
                    return value
                raise ValueError(
                    "Value {} should be between 0 and 1.".format(value))

            self._update_tunables_attr('target', check_fraction(target))
            self._tuned = 0
            return target

        def update_moves(value):
            self._update_tunables(new_moves=value)
            self._tuned = 0
            return value

        def update_types(value):
            self._update_tunables(new_types=value)
            self._tuned = 0
            return value

        # A flag for knowing when to update the maximum move sizes
        self._update_move_sizes = False

        self._tunables = []
        # A counter when tuned reaches 1 it means that the tuner has reported
        # being tuned one time in a row. However, as the first run of the tuner
        # is likely at timestep 0 which means that the counters are (0, 0) and
        # _MoveSizeTuneDefinition returns y == target for that case, we need two
        # rounds of tuning to be sure that we have converged. Since, in general,
        # solvers do not do much if any work on already tuned tunables, this is
        # not a performance problem.
        self._tuned = 0
        self._is_attached = False

        # set up maximum trial move sizes
        def flag_move_size_update(value):
            self._update_move_sizes = True
            return value

        t_moves = TypeParameter(
            'max_translation_move', 'particle_type',
            TypeParameterDict(
                OnlyType(
                    float, postprocess=flag_move_size_update, allow_none=True),
                len_keys=1)
            )
        r_moves = TypeParameter(
            'max_rotation_move', 'particle_type',
            TypeParameterDict(
                OnlyType(
                    float, postprocess=flag_move_size_update, allow_none=True),
                len_keys=1)
            )
        self._typeparam_dict = {'max_translation_move': t_moves,
                                'max_rotation_move': r_moves}

        # This is a bit complicated because we are having to ensure that we keep
        # the list of tunables and the solver updated with the changes to
        # attributes. However, these are simply forwarding a change along.
        param_dict = ParameterDict(
            moves=OnlyIf(to_type_converter([OnlyFrom(['a', 'd'])]),
                         postprocess=update_moves),
            types=OnlyIf(to_type_converter([str]),
                         postprocess=update_types,
                         allow_none=True),
            target=OnlyType(float, postprocess=target_postprocess),
            solver=SolverStep
            )

        self._param_dict.update(param_dict)
        self.target = target
        self.solver = solver
        self.moves = moves
        self.types = types

        self.max_rotation_move.default = max_rotation_move
        self.max_translation_move.default = max_translation_move
        if types is not None:
            self._update_tunables(new_moves=moves, new_types=types)