Example #1
0
def test_restart(gap_fct, node_positions, mesh_size, score_nodal_points,
                 use_fake_potential):
    """
    Test that the calculation is done when restarting from a finished result.
    """
    def invalid_gap_fct(x):
        raise ValueError

    with tempfile.NamedTemporaryFile() as named_file:
        result = run(gap_fct=gap_fct,
                     save_file=named_file.name,
                     initial_mesh_size=mesh_size,
                     use_fake_potential=use_fake_potential)
        score_nodal_points(result,
                           exact_points=node_positions,
                           cutoff_accuracy=1e-6,
                           cutoff_coverage=1e-6,
                           additional_tag='initial_')

        restart_result = run(gap_fct=invalid_gap_fct,
                             save_file=named_file.name,
                             load=True,
                             load_quiet=False,
                             initial_mesh_size=mesh_size,
                             use_fake_potential=use_fake_potential)
        score_nodal_points(restart_result,
                           exact_points=node_positions,
                           cutoff_accuracy=1e-6,
                           cutoff_coverage=1e-6,
                           additional_tag='restart_')
Example #2
0
def test_restart_partial(gap_fct, node_positions, mesh_size):
    """
    Test that no additional refinement is done when restarting with a forced
    initial mesh.
    """
    with tempfile.NamedTemporaryFile() as named_file:
        refinement_stencil = nf.search.refinement_stencil.get_mesh_stencil(
            mesh_size=[1, 1, 1])
        result = run(gap_fct=gap_fct,
                     save_file=named_file.name,
                     initial_mesh_size=mesh_size,
                     use_fake_potential=False,
                     refinement_stencil=refinement_stencil)
        # number of starting points + one refinement per node
        assert (len(result.nodes) == np.prod(mesh_size) +
                len(node_positions) * len(refinement_stencil))
        result2 = run(gap_fct=gap_fct,
                      save_file=named_file.name,
                      initial_mesh_size=mesh_size,
                      load=True,
                      use_fake_potential=False,
                      refinement_stencil=refinement_stencil,
                      force_initial_mesh=True)
        assert (len(result2.nodes) == 2 * np.prod(mesh_size) +
                len(node_positions) * len(refinement_stencil))
Example #3
0
def test_raises():
    """
    Test that using an invalid gap_fct raises the error.
    """
    async def gap_fct(pos):  # pylint: disable=unused-argument
        raise ValueError('test error.')

    with pytest.raises(ValueError):
        run(gap_fct)
def test_nodal_line_nonperiodic(
    nodal_line_nonperiodic_properties, score_nodal_line
):  # pylint: disable=redefined-outer-name,invalid-name
    """
    Test a nodal line of a non-periodic potential.
    """
    dist_fct, gap_fct, parametrization = nodal_line_nonperiodic_properties

    result = run(
        gap_fct=gap_fct,
        limits=[(-1, 1)] * 2,
        gap_threshold=1e-3,
        feature_size=0.2,
        refinement_mesh_size=3,
        initial_mesh_size=3,
        use_fake_potential=True,
        periodic=False
    )
    score_nodal_line(
        result=result,
        dist_func=dist_fct,
        line_parametrization=parametrization,
        cutoff_accuracy=2e-3,
        cutoff_coverage=0.2,
    )
Example #5
0
def test_save(gap_fct, node_positions, mesh_size, use_fake_potential,
              score_nodal_points):
    """
    Test saving to a file
    """
    with tempfile.NamedTemporaryFile() as named_file:
        result = run(
            gap_fct=gap_fct,
            save_file=named_file.name,
            initial_mesh_size=mesh_size,
            use_fake_potential=use_fake_potential,
        )
        score_nodal_points(result,
                           exact_points=node_positions,
                           cutoff_accuracy=1e-6,
                           cutoff_coverage=1e-6)
Example #6
0
def test_simple(
    gap_fct,
    node_positions,
    mesh_size,
    use_fake_potential,
    score_nodal_points,
):
    """
    Test that a single nodal point is found.
    """
    result = run(gap_fct=gap_fct,
                 initial_mesh_size=mesh_size,
                 use_fake_potential=use_fake_potential)
    score_nodal_points(result,
                       exact_points=node_positions,
                       cutoff_accuracy=1e-6,
                       cutoff_coverage=1e-6)
Example #7
0
def test_nodal_surface(nodal_surface_properties, score_nodal_surface):  # pylint: disable=redefined-outer-name
    """
    Test that a nodal surface is found.
    """
    dist_fct, gap_fct, parametrization = nodal_surface_properties

    result = run(
        gap_fct=gap_fct,
        gap_threshold=1e-4,
        feature_size=1e-1,
        refinement_stencil=get_mesh_stencil(mesh_size=(2, 2, 2)),
        initial_mesh_size=(3, 3, 3),
        use_fake_potential=False,
    )
    score_nodal_surface(
        result=result,
        dist_func=dist_fct,
        surface_parametrization=parametrization,
        cutoff_accuracy=2e-3,
        cutoff_coverage=1e-1,
    )
Example #8
0
def test_nodal_line(nodal_line_properties, score_nodal_line):  # pylint: disable=redefined-outer-name
    """
    Test that a single nodal line is found.
    """
    dist_fct, gap_fct, parametrization = nodal_line_properties

    result = run(
        gap_fct=gap_fct,
        gap_threshold=2e-4,
        feature_size=0.05,
        refinement_stencil='auto',
        initial_mesh_size=(3, 3, 3),
        use_fake_potential=True,
    )
    score_nodal_line(
        result=result,
        dist_func=dist_fct,
        line_parametrization=parametrization,
        cutoff_accuracy=2e-3,
        cutoff_coverage=0.05,
    )
Example #9
0
def test_nodal_line_2d(nodal_line_2d_properties, score_nodal_line):  # pylint: disable=redefined-outer-name
    """
    Test that two 2D nodal lines are correctly identified.
    """
    dist_fct, gap_fct, parametrization = nodal_line_2d_properties

    result = run(
        gap_fct=gap_fct,
        limits=[(0, 2 * np.pi), (0, 2 * np.pi)],
        gap_threshold=2e-4,
        feature_size=0.05,
        refinement_stencil='auto',
        initial_mesh_size=3,
        use_fake_potential=True,
    )
    score_nodal_line(
        result=result,
        dist_func=dist_fct,
        line_parametrization=parametrization,
        cutoff_accuracy=2e-3,
        cutoff_coverage=0.05,
    )
Example #10
0
def test_nodal_line_1d(nodal_line_1d_properties, score_nodal_line):  # pylint: disable=redefined-outer-name
    """
    Test that searching a nodal line in 1D works.
    """
    dist_fct, gap_fct, parametrization = nodal_line_1d_properties

    result = run(
        gap_fct=gap_fct,
        limits=[(0, 1)],
        gap_threshold=2e-4,
        feature_size=0.05,
        refinement_stencil='auto',
        initial_mesh_size=3,
        use_fake_potential=True,
    )
    score_nodal_line(
        result=result,
        dist_func=dist_fct,
        line_parametrization=parametrization,
        cutoff_accuracy=2e-3,
        cutoff_coverage=0.05,
    )