示例#1
0
    def secant_solver(cls,
                      trigger,
                      moves,
                      target,
                      types=None,
                      max_translation_move=None,
                      max_rotation_move=None,
                      gamma=0.8,
                      tol=1e-2):
        """Create a `MoveSize` tuner with a `hoomd.tune.SecantSolver`.

        This solver can be faster than `hoomd.tune.ScaleSolver`, but depending
        on the system slightly less stable. In general, with the default value
        of gamma this should not be a problem.

        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, defaults to ``None`` which represents no
                maximum move size.
            max_rotation_move (float): The maximum value of a rotational move
                size to attempt, defaults to ``None`` which represents no
                maximum move size.
            gamma (float): The value of gamma to pass through
                to `hoomd.tune.SecantSolver`. Controls the size of corrections
                to the move size (smaller values increase stability). Should be
                between 0 and 1, defaults to 0.8.
            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.

        Note:
            Increasing ``gamma`` towards 1 does not necessarily speed up
            convergence and can slow it done. In addition, large values of
            ``gamma`` can make the solver unstable especially when tuning
            frequently.
        """
        solver = SecantSolver(gamma, tol)
        return cls(trigger, moves, target, solver, types, max_translation_move,
                   max_rotation_move)
示例#2
0
    def secant_solver(cls,
                      trigger,
                      target,
                      max_chain_time=None,
                      gamma=0.8,
                      tol=1e-2):
        """Create a `ChainTime` tuner with a `hoomd.tune.SecantSolver`.

        This solver can be faster than `hoomd.tune.ScaleSolver`, but depending
        on the system slightly less stable. In general, with the default value
        of gamma this should not be a problem.

        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,
                defaults to ``None`` which represents no maximum chain time.
            gamma (float): The value of gamma to pass through
                to `hoomd.tune.SecantSolver`. Controls the size of corrections
                to the move size (smaller values increase stability). Should be
                between 0 and 1, defaults to 0.8.
            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.

        Note:
            Increasing ``gamma`` towards 1 does not necessarily speed up
            convergence and can slow it done. In addition, large values of
            ``gamma`` can make the solver unstable especially when tuning
            frequently.
        """
        solver = SecantSolver(gamma, tol)
        return cls(trigger, target, solver, max_chain_time)
示例#3
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)