Ejemplo n.º 1
0
    def scale_solver(cls,
                     trigger,
                     target,
                     max_chain_time=None,
                     max_scale=2.,
                     gamma=1.,
                     tol=1e-2):
        """Create a `ChainTime` tuner with a `hoomd.tune.ScaleSolver`.

        Args:
            trigger (hoomd.trigger.Trigger): ``Trigger`` to determine when to
                run the tuner.
            target (float): The number of collisions in a chain that is
                desired.
            max_chain_time (float): The maximum value of chain time to attempt.
            max_scale (float): The maximum amount to scale the current
                chain_time value with.
            gamma (float): The value of gamma to pass through to
                `hoomd.tune.ScaleSolver`. Controls the size of corrections to
                the move size (larger values increase stability while increasing
                convergence time).
            tol (float): The absolute tolerance to allow between the current
                acceptance rate and the target before the move sizes are
                considered tuned. The tolerance should not be too much lower
                than the default of 0.01 as acceptance rates can vary
                significantly at typical tuning rates.
        """
        solver = ScaleSolver(max_scale, gamma, 'positive', tol)
        return cls(trigger, target, solver, max_chain_time)
Ejemplo n.º 2
0
    def scale_solver(cls, trigger, moves, target,
                     types=None, max_translation_move=None,
                     max_rotation_move=None,
                     max_scale=2., gamma=1., tol=1e-2):
        """Create a `MoveSize` tuner with a `hoomd.tune.ScaleSolver`.

        Args:
            trigger (hoomd.trigger.Trigger): ``Trigger`` to determine when to
                run the tuner.
            moves (list[str]): A list of types of moves to tune. Available
                options are 'a' and 'd'.
            target (float): The acceptance rate for trial moves that is desired.
                The value should be between 0 and 1.
            types (list[str]): A list of string particle types to tune the
                move size for, defaults to None which upon attaching will tune
                all types in the system currently.
            max_translation_move (float): The maximum value of a translational
                move size to attempt.
            max_rotation_move (float): The maximum value of a rotational move
                size to attempt.
            gamma (float): The value of gamma to pass through to
                `hoomd.tune.ScaleSolver`. Controls the size of corrections to
                the move size (larger values increase stability while increasing
                convergence time).
            tol (float): The absolute tolerance to allow between the current
                acceptance rate and the target before the move sizes are
                considered tuned. The tolerance should not be too much lower
                than the default of 0.01 as acceptance rates can vary
                significantly at typical tuning rates.
        """
        solver = ScaleSolver(max_scale, gamma, 'negative', tol)
        return cls(trigger, moves, target, solver, types,
                   max_translation_move, max_rotation_move)
Ejemplo n.º 3
0
    def scale_solver(cls,
                     trigger,
                     boxmc,
                     moves,
                     target,
                     max_move_size=None,
                     max_scale=2.,
                     gamma=1.,
                     tol=1e-2):
        """Create a `BoxMCMoveSize` tuner with a `hoomd.tune.ScaleSolver`.

        Args:
            trigger (hoomd.trigger.Trigger): ``Trigger`` to determine when to
                run the tuner.
            boxmc (hoomd.hpmc.update.BoxMC): The `hoomd.hpmc.update.BoxMC`
                object to tune.
            moves (list[str]): A list of types of moves to tune. Available
                options are 'a' and 'd'.
            target (float): The acceptance rate for trial moves that is desired.
                The value should be between 0 and 1.
            max_move_size (float): The maximum value of a volume
                move size to attempt.
            max_scale (float): Maximum scale factor.
            gamma (float): The value of gamma to pass through to
                `hoomd.tune.ScaleSolver`. Controls the size of corrections to
                the move size (larger values increase stability while increasing
                convergence time).
            tol (float): The absolute tolerance to allow between the current
                acceptance rate and the target before the move sizes are
                considered tuned. The tolerance should not be too much lower
                than the default of 0.01 as acceptance rates can vary
                significantly at typical tuning rates.
        """
        solver = ScaleSolver(max_scale, gamma, 'negative', tol)
        return cls(trigger, boxmc, moves, target, solver, max_move_size)
Ejemplo n.º 4
0
                              (None, [(1000, True), (-1000, True)])]
        for domain, check_pairs in domain_check_pairs:
            attr_definition.domain = domain
            for x, in_domain in check_pairs:
                assert in_domain == attr_definition.in_domain(x)

    def test_hash(self, attr_definition, alternate_definition):
        assert hash(attr_definition) == hash(attr_definition)
        assert hash(attr_definition) != hash(alternate_definition)

    def test_eq(self, attr_definition, alternate_definition):
        assert attr_definition == attr_definition
        assert attr_definition != alternate_definition


@pytest.fixture(params=[ScaleSolver(), SecantSolver()],
                ids=lambda solver: solver.__class__.__name__)
def solver(request):
    return request.param


@pytest.fixture
def equation_definition():
    """x^2 - 1, x = (1, -1)"""
    equation = dict(x=4)
    equation['y'] = lambda: equation['x']**2
    return ManualTuneDefinition(get_x=lambda: equation['x'],
                                set_x=lambda x: equation.__setitem__('x', x),
                                get_y=lambda: equation['y'](),
                                target=1)