def __init__(self, moves, target, solver, types=None, max_translation_move=None, max_rotation_move=None): super().__init__(target, solver) # A flag for knowing when to update the maximum move sizes self._should_update_move_sizes = False # set up maximum trial move sizes t_moves = TypeParameter( 'max_translation_move', 'particle_type', TypeParameterDict(OnlyTypes( float, postprocess=self._flag_move_size_update, allow_none=True), len_keys=1)) r_moves = TypeParameter( 'max_rotation_move', 'particle_type', TypeParameterDict(OnlyTypes( float, postprocess=self._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=self._update_moves), types=OnlyIf(to_type_converter([str]), postprocess=self._update_types, allow_none=True), ) 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)
def __init__(self, filter, kT, tau, S, tauS, couple, box_dof=[True,True,True,False,False,False], rescale_all=False, gamma=0.0): # store metadata param_dict = ParameterDict( filter=ParticleFilter, kT=Variant, tau=float(tau), S=OnlyIf(to_type_converter((Variant,)*6), preprocess=self._preprocess_stress), tauS=float(tauS), couple=str(couple), box_dof=[bool,]*6, rescale_all=bool(rescale_all), gamma=float(gamma), translational_thermostat_dof=(float, float), rotational_thermostat_dof=(float, float), barostat_dof=(float, float, float, float, float, float) ) param_dict.update( dict(filter=filter, kT=kT, S=S, couple=couple, box_dof=box_dof, translational_thermostat_dof=(0, 0), rotational_thermostat_dof=(0, 0), barostat_dof=(0, 0, 0, 0, 0, 0))) # set defaults self._param_dict.update(param_dict)
def __init__(self, filter, S, tauS, couple, box_dof=(True, True, True, False, False, False), rescale_all=False, gamma=0.0): # store metadata param_dict = ParameterDict(filter=ParticleFilter, kT=Variant, S=OnlyIf( to_type_converter((Variant, ) * 6), preprocess=self._preprocess_stress), tauS=float, couple=str, box_dof=(bool, ) * 6, rescale_all=bool, gamma=float, barostat_dof=(float, ) * 6) param_dict.update( dict(filter=filter, kT=hoomd.variant.Constant(1.0), S=S, tauS=float(tauS), couple=str(couple), box_dof=tuple(box_dof), rescale_all=bool(rescale_all), gamma=float(gamma), barostat_dof=(0.0, 0.0, 0.0, 0.0, 0.0, 0.0))) # set defaults self._param_dict.update(param_dict)
def __setitem__(self, key, value): """Set parameter by key.""" if key not in self._type_converter.keys(): self._dict[key] = value self._type_converter[key] = to_type_converter(value) else: self._dict[key] = self._type_converter[key](value)
def __init__(self,N,epsilon=0): # store metadata param_dict = ParameterDict( N=OnlyIf(to_type_converter((int,)*3), preprocess=self._preprocess_unitcell), epsilon=float(epsilon), ) param_dict['N'] = N self._param_dict.update(param_dict)
def __init__(self, schema, data): self._data = data validator = typeconverter.to_type_converter(schema) self._sync_data = {} for key in data: self._sync_data[key] = collections._to_hoomd_data( root=self, schema=validator[key], parent=None, identity=key, data=data[key], )
def __init__(self): param_dict = ParameterDict(size=int, types=OnlyIf( to_type_converter([str]), preprocess=self._preprocess_type)) param_dict["types"] = ["mesh"] param_dict["size"] = 0 self._triangles = np.empty([0, 3], dtype=int) self._param_dict.update(param_dict)
def __init__(self, _defaults=_NoDefault, **kwargs): self._cpp_obj = None self._dict = {} self._getters = {} self._setters = {} # This if statement is necessary to avoid a RecursionError from Python's # collections.abc module. The reason for this error is not clear but # results from an isinstance check of an empty dictionary. if len(kwargs) != 0: self._type_converter = to_type_converter(kwargs) for key, value in _to_base_defaults(kwargs, _defaults).items(): self._dict[key] = self._to_hoomd_data(key, value) else: self._type_converter = {}
def __init__(self): body = TypeParameter( "body", "particle_types", TypeParameterDict(OnlyIf(to_type_converter({ 'constituent_types': [str], 'positions': [(float, ) * 3], 'orientations': [(float, ) * 4], 'charges': [float], 'diameters': [float] }), allow_none=True), len_keys=1)) self._add_typeparam(body) self.body.default = None
def __setitem__(self, key, value): """Set parameter by key.""" if key not in self._type_converter.keys(): if self._attached: raise KeyError("Keys cannot be added after Simulation.run().") self._type_converter[key] = to_type_converter(value) validated_value = self._type_converter[key](value) if self._attached: try: self._cpp_setting(key, validated_value) except (AttributeError): raise MutabilityError(key) if key in self._dict and isinstance(self._dict[key], _HOOMDSyncedCollection): self._dict[key]._isolate() self._dict[key] = self._to_hoomd_data(key, validated_value)
def __init__(self, *args, **kwargs): _defaults = kwargs.pop('_defaults', _NoDefault) if len(kwargs) != 0 and len(args) != 0: raise ValueError("An unnamed argument and keyword arguments " "cannot both be specified.") if len(kwargs) == 0 and len(args) == 0: raise ValueError("Either an unnamed argument or keyword " "arguments must be specified.") if len(args) > 1: raise ValueError("Only one unnamed argument allowed.") if len(kwargs) > 0: default_arg = kwargs else: default_arg = args[0] self._type_converter = to_type_converter(default_arg) self._default = _to_default(default_arg, _defaults)
def _set_validation_and_defaults(self, *args, **kwargs): defaults = kwargs.pop('_defaults', _NoDefault) if len(kwargs) != 0 and len(args) != 0: raise ValueError("Positional argument(s) and keyword argument(s) " "cannot both be specified.") if len(kwargs) == 0 and len(args) == 0: raise ValueError("Either a positional or keyword " "argument must be specified.") if len(args) > 1: raise ValueError("Only one positional argument allowed.") if len(kwargs) > 0: type_spec = kwargs else: type_spec = args[0] self._type_converter = to_type_converter(type_spec) self._default = _to_default(type_spec, defaults)
def __init__( self, boxmc, moves, target, solver, max_move_size=None, ): super().__init__(target, solver) # Flags for knowing when to update classes attributes self._update_move_sizes = False self._should_update_tunables = False # 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. params = ParameterDict( boxmc=hoomd.hpmc.update.BoxMC, moves=[ OnlyFrom(_MoveSizeTuneDefinition.acceptable_attrs, postprocess=self._flag_new_tunables) ], max_move_size=OnlyIf( to_type_converter({ attr: OnlyTypes(float, allow_none=True, postprocess=self._flag_move_size_update) for attr in _MoveSizeTuneDefinition.acceptable_attrs }),)) params["boxmc"] = boxmc params["moves"] = moves if max_move_size is None: max_move_size = { attr: None for attr in _MoveSizeTuneDefinition.acceptable_attrs } params["max_move_size"] = max_move_size self._param_dict.update(params) self._update_tunables()
def __init__(self, nlist, default_r_cut=None, mode='none'): super().__init__(nlist, default_r_cut, mode) params = TypeParameter( 'params', 'particle_types', TypeParameterDict(epsilon=float, sigma_i=float, sigma_j=float, alpha=int, contact_ratio_i=0.15, contact_ratio_j=0.15, average_simplices=True, len_keys=2)) shape = TypeParameter( 'shape', 'particle_types', TypeParameterDict(vertices=[(float, float, float)], faces=[[int]], rounding_radii=OnlyIf( to_type_converter((float, float, float)), preprocess=self._to_three_tuple), len_keys=1)) self._extend_typeparam((params, shape))
def __init__(self, _defaults=_NoDefault, **kwargs): self._type_converter = to_type_converter(kwargs) self._dict = {**_to_base_defaults(kwargs, _defaults)}
def __setitem__(self, key, value): if key not in self._type_converter.keys(): super().__setitem__(key, value) self._type_converter[key] = to_type_converter(value) else: super().__setitem__(key, self._type_converter[key](value))
def __init__(self, _defaults=NoDefault, **kwargs): self._type_converter = to_type_converter(kwargs) super().__init__(**to_base_defaults(kwargs, _defaults))
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(OnlyTypes(float, postprocess=flag_move_size_update, allow_none=True), len_keys=1)) r_moves = TypeParameter( 'max_rotation_move', 'particle_type', TypeParameterDict(OnlyTypes(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=OnlyTypes(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)
def __setitem__(self, key, value): if key not in self._type_converter.keys(): self._dict[key] = value self._type_converter[key] = to_type_converter(value) else: self._dict[key] = self._type_converter[key](value)