Last login: Thu Apr 27 15:14:43 on ttys000 faruk@Faruks-MacBook-Air ~ % conda activate myKwant (myKwant) faruk@Faruks-MacBook-Air ~ % python3 Python 3.11.3 | packaged by conda-forge | (main, Apr 6 2023, 08:58:31) [Clang 14.0.6 ] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> kwant.test() Traceback (most recent call last): File "", line 1, in NameError: name 'kwant' is not defined >>> import kwant >>> kwant.test() ================================== test session starts =================================== platform darwin -- Python 3.11.3, pytest-7.3.1, pluggy-1.0.0 -- /Users/faruk/miniconda3/envs/myKwant/bin/python3 cachedir: .pytest_cache rootdir: /Users/faruk plugins: anyio-3.5.0 collected 364 items miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_common.py::test_sympify[k_x * A(x) * k_x-output_expr0] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_common.py::test_sympify[[[k_x * A(x) * k_x]]-output_expr1] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_common.py::test_sympify[k_x * sigma_y + k_y * sigma_x-output_expr2] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_common.py::test_sympify[[[k_x*A(x)*k_x, B(x, y)*k_x], [k_x*B(x, y), C*k_y**2]]-output_expr3] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_common.py::test_sympify[kron(sigma_x, sigma_y)-output_expr4] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_common.py::test_sympify[identity(2)-output_expr5] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_common.py::test_sympify[eye(2)-output_expr6] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_common.py::test_sympify[1 * sigma_x + 2 * sigma_y + 3 * sigma_z-output_expr7] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_common.py::test_sympify_substitutions[k_x-output_expr0-subs0] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_common.py::test_sympify_substitutions[x-output_expr1-subs1] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_common.py::test_sympify_substitutions[A-output_expr2-subs2] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_common.py::test_sympify_substitutions[A-output_expr3-subs3] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_common.py::test_sympify_substitutions[A-output_expr4-subs4] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_common.py::test_sympify_invalid_substitutions[subs0] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_common.py::test_sympify_invalid_substitutions[subs1] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_common.py::test_sympify_invalid_substitutions[subs2] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_common.py::test_sympify_invalid_substitutions[subs3] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_common.py::test_sympify_mix_symbol_and_matrx[A + k_x**2 * eye(2)-output_expr0-subs0] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_common.py::test_sympify_mix_symbol_and_matrx[A + k_x**2 * identity(2)-output_expr1-subs1] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_common.py::test_make_commutative PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_common.py::test_monomials[expr0-None-output0] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_common.py::test_monomials[expr1-gens1-output1] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_common.py::test_monomials[expr2-gens2-output2] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_common.py::test_monomials[expr3-gens3-output3] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_common.py::test_monomials[expr4-x-output4] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_common.py::test_monomials[expr5-x-output5] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_common.py::test_monomials[expr6-x-output6] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_common.py::test_monomials[expr7-xy-output7] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_common.py::test_monomials[expr8-ab-output8] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_common.py::test_monomials[expr9-None-output9] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_common.py::test_monomials[expr10-gens10-output10] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_common.py::test_monomials[expr11-gens11-output11] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_common.py::test_lambdify[x+y--kwargs0] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_common.py::test_lambdify[1--kwargs1] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_common.py::test_lambdify[f(x)--kwargs2] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_common.py::test_lambdify[e3--kwargs3] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_common.py::test_lambdify[[[f(x)]]--kwargs4] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_common.py::test_lambdify_substitutions[x + y-kwargs0] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_common.py::test_lambdify_substitutions[e1-kwargs1] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_reading_coordinates[True] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_reading_coordinates[False] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_reading_coordinates_matrix PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_reading_different_matrix_types PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_simple_derivations[True] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_simple_derivations[False] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_simple_derivations_with_subs[A * k_x-(A + B) * k_x-subs0] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_simple_derivations_with_subs[k_x-k_x + k_y-subs1] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_simple_derivations_with_subs[k_x**2 + V-k_x**2 + V + V_0-subs2] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_simple_derivations_with_subs[k_x**2 + A + C-k_x**2 + B + 5-subs3] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_simple_derivations_with_subs[x + y + z-1 + 3 + 5-subs4] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_simple_derivations_matrix PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_integer_float_input PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_different_discrete_coordinates PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_non_expended_input PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_matrix_with_zeros PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_numeric_functions_basic_symbolic PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_numeric_function_coords_from_site[True] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_numeric_function_coords_from_site[False] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_numeric_functions_not_discrete_coords PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_numeric_functions_advanced[pi-3.141592653589793-params0] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_numeric_functions_advanced[A + pi-4.141592653589793-params1] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_numeric_functions_advanced[A + B(pi)-4.141592653589793-params2] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_numeric_functions_advanced[A + I-(1+1j)-params3] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_numeric_functions_advanced[A + 1j-(1+1j)-params4] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_numeric_functions_advanced[A + B(I)-(1+1j)-params5] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_numeric_functions_advanced[A + B(1j)-(1+1j)-params6] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_numeric_functions_advanced[exp(1j * pi)-(-1+1.2246467991473532e-16j)-params7] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_numeric_functions_advanced[ham8-(-1+1.2246467991473532e-16j)-params8] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_numeric_functions_basic_string PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_numeric_functions_with_subs[A * k_x + A-(A + B) * k_x + A + B-subs0] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_onsite_hopping_function_name PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_numeric_functions_advance PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_numeric_functions_with_parameter PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_grid[k_x-None-grid0] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_grid[k_x * sigma_z-None-grid1] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_grid[k_x-0.5-grid2] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_grid[k_x**2 + k_y**2-2-grid3] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_grid_input[k_x-None-0-None] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_grid_input[k_x-None-0-1] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_grid_input[k_x * eye(2)-None-0-2] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_grid_input[k_x-grid_offset3-0-None] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_grid_input[k_x-grid_offset4-1-None] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_grid_input[k_x + k_y-None-offset5-None] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_grid_input[k_x + k_y-grid_offset6-offset6-None] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_grid_input[k_x + k_y-grid_offset7-offset7-None] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_grid_offset_passed_to_functions PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_grid_constraints[k_x-None-grid0] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_grid_constraints[k_x-xy-grid1] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_grid_constraints[k_x-None-grid2] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_grid_constraints[k_x * eye(2)-None-grid3] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_grid_constraints[k_x+k_y-None-grid4] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_check_symbol_names[1] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_check_symbol_names[1a] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_check_symbol_names[-a] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_check_symbol_names[+a] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_check_symbol_names[while] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_check_symbol_names[for] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/continuum/tests/test_discretizer.py::test_rectangular_grid PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/graph/tests/test_core.py::test_empty PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/graph/tests/test_core.py::test_num_nodes PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/graph/tests/test_core.py::test_large PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/graph/tests/test_core.py::test_small PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/graph/tests/test_core.py::test_negative_node_ids PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/graph/tests/test_core.py::test_add_edges PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/graph/tests/test_core.py::test_edge_ids PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/graph/tests/test_core.py::test_pickle PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/linalg/tests/test_linalg.py::test_gen_eig SKIPPED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/linalg/tests/test_linalg.py::test_lu PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/linalg/tests/test_linalg.py::test_rcond_from_lu PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/linalg/tests/test_linalg.py::test_schur SKIPPED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/linalg/tests/test_linalg.py::test_convert_r2c_schur PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/linalg/tests/test_linalg.py::test_order_schur PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/linalg/tests/test_linalg.py::test_evecs_from_schur PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/linalg/tests/test_linalg.py::test_gen_schur SKIPPED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/linalg/tests/test_linalg.py::test_convert_r2c_gen_schur SKIPPED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/linalg/tests/test_linalg.py::test_order_gen_schur SKIPPED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/linalg/tests/test_linalg.py::test_evecs_from_gen_schur SKIPPED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/linalg/tests/test_lll.py::test_lll PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/linalg/tests/test_lll.py::test_cvp PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/linalg/tests/test_mumps.py::test_lu_with_dense FAILED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/linalg/tests/test_mumps.py::test_schur_complement_with_dense PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/linalg/tests/test_mumps.py::test_error_minus_9 PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/linalg/tests/test_mumps.py::test_factor_warning PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_dispersion.py::test_band_energies PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_dispersion.py::test_same_as_lead PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_dispersion.py::test_raise_nonhermitian PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_dispersion.py::test_band_velocities PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_dispersion.py::test_band_velocity_derivative PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_dispersion.py::test_eigenvector_calculation PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_dispersion.py::test_raise_implemented PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_phases[square-finite-1] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_phases[square-finite-2] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_phases[square-finite-3] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_phases[square-infinite-1] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_phases[square-infinite-2] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_phases[square-infinite-3] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_phases[honeycomb-finite-1] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_phases[honeycomb-finite-2] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_phases[honeycomb-finite-3] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_phases[honeycomb-infinite-1] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_phases[honeycomb-infinite-2] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_phases[honeycomb-infinite-3] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_phases[cubic-finite-1] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_phases[cubic-finite-2] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_phases[cubic-finite-3] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_phases[cubic-infinite-1] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_phases[cubic-infinite-2] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_phases[cubic-infinite-3] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_phases_composite[square-1] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_phases_composite[square-2] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_phases_composite[square-3] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_phases_composite[honeycomb-1] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_phases_composite[honeycomb-2] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_phases_composite[honeycomb-3] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_overlapping_interfaces[1] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_overlapping_interfaces[2] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_unfixable_gauge PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_invalid_lead PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_minimal_cycle_basis[1-square-rectangle] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_minimal_cycle_basis[1-square-circle] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_minimal_cycle_basis[1-square-half-ring] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_minimal_cycle_basis[1-honeycomb-rectangle] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_minimal_cycle_basis[1-honeycomb-circle] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_minimal_cycle_basis[1-honeycomb-half-ring] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_minimal_cycle_basis[2-square-rectangle] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_minimal_cycle_basis[2-square-circle] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_minimal_cycle_basis[2-square-half-ring] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_minimal_cycle_basis[2-honeycomb-rectangle] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_minimal_cycle_basis[2-honeycomb-circle] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_minimal_cycle_basis[2-honeycomb-half-ring] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_minimal_cycle_basis[3-square-rectangle] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_minimal_cycle_basis[3-square-circle] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_minimal_cycle_basis[3-square-half-ring] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_minimal_cycle_basis[3-honeycomb-rectangle] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_minimal_cycle_basis[3-honeycomb-circle] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_minimal_cycle_basis[3-honeycomb-half-ring] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_constant_surface_integral PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_invariant_surface_integral PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_uniform_magnetic_field[0] FAILED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_uniform_magnetic_field[0.1] FAILED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_uniform_magnetic_field[] FAILED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_phase_sign FAILED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_leads.py::test_analytic_numeric PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_leads.py::test_regular_fully_degenerate PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_leads.py::test_regular_degenerate_with_crossing PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_leads.py::test_singular PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_leads.py::test_singular_but_square PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_leads.py::test_singular_fully_degenerate PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_leads.py::test_singular_degenerate_with_crossing PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_leads.py::test_singular_h_and_t PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_leads.py::test_modes PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_leads.py::test_modes_bearded_ribbon PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_leads.py::test_symm_algorithm_equivalence PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_leads.py::test_for_all_evs_equal PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_leads.py::test_dtype_linsys PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_leads.py::test_zero_hopping PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_leads.py::test_momenta PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_leads.py::test_PHS_TRIM_degenerate_ordering PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_leads.py::test_modes_symmetries PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_leads.py::test_chiral_symm PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_leads.py::test_PHS_TRIM PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_leads.py::test_cons_singular_hopping PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_leads.py::test_cons_rectangular_hopping PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_leads.py::test_cons_blocks_sizes PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_leads.py::test_block_relations_cons_PHS PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_leads.py::test_blocks_symm_complex_projectors PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_noise.py::test_multiterminal_input PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_noise.py::test_twoterminal FAILED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_symmetry.py::test_projectors PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_symmetry.py::test_set_discrete_symm PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_symmetry.py::test_projectors_and_symmetry PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_symmetry.py::test_validate PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_symmetry.py::test_validate_commutator PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/test_mumps.py::test_output FAILED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/test_mumps.py::test_one_lead FAILED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/test_mumps.py::test_smatrix_shape PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/test_mumps.py::test_two_equal_leads FAILED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/test_mumps.py::test_graph_system FAILED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/test_mumps.py::test_singular_graph_system FAILED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/test_mumps.py::test_tricky_singular_hopping FAILED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/test_mumps.py::test_many_leads FAILED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/test_mumps.py::test_selfenergy FAILED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/test_mumps.py::test_selfenergy_reflection FAILED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/test_mumps.py::test_very_singular_leads PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/test_mumps.py::test_ldos FAILED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/test_mumps.py::test_wavefunc_ldos_consistency PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/test_mumps.py::test_arg_passing PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/test_sparse.py::test_output PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/test_sparse.py::test_one_lead PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/test_sparse.py::test_smatrix_shape PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/test_sparse.py::test_two_equal_leads PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/test_sparse.py::test_graph_system PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/test_sparse.py::test_singular_graph_system PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/test_sparse.py::test_tricky_singular_hopping PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/test_sparse.py::test_many_leads PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/test_sparse.py::test_selfenergy PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/test_sparse.py::test_selfenergy_reflection PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/test_sparse.py::test_very_singular_leads PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/test_sparse.py::test_ldos PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/test_sparse.py::test_wavefunc_ldos_consistency PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/test_sparse.py::test_arg_passing PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_builder.py::test_bad_keys PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_builder.py::test_site_families PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_builder.py::test_construction_and_indexing PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_builder.py::test_hermitian_conjugation[value0] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_builder.py::test_hermitian_conjugation[value1] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_builder.py::test_hermitian_conjugation[value2] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_builder.py::test_hermitian_conjugation[value3] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_builder.py::test_value_equality_and_identity PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_builder.py::test_finalization PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_builder.py::test_site_ranges PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_builder.py::test_hamiltonian_evaluation PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_builder.py::test_dangling PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_builder.py::test_builder_with_symmetry PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_builder.py::test_fill PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_builder.py::test_fill_sticky PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_builder.py::test_attach_lead PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_builder.py::test_attach_lead_incomplete_unit_cell PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_builder.py::test_neighbors_not_in_single_domain PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_builder.py::test_closest PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_builder.py::test_update PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_builder.py::test_HoppingKind PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_builder.py::test_invalid_HoppingKind PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_builder.py::test_ModesLead_and_SelfEnergyLead FAILED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_builder.py::test_site_pickle PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_builder.py::test_discrete_symmetries PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_builder.py::test_argument_passing PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_builder.py::test_parameter_substitution PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_builder.py::test_subs PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_builder.py::test_attach_stores_padding PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_builder.py::test_finalization_preserves_padding PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_comprehensive.py::test_qhe FAILED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_kpm.py::test_mean_SD PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_kpm.py::test_conductivity PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_kpm.py::test_where PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_kpm.py::test_vector_factory PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_kpm.py::test_api_ham PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_kpm.py::test_api_operator PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_kpm.py::test_api_single_eigenvalue_error PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_kpm.py::test_energy_resolution PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_kpm.py::test_operator_none PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_kpm.py::test_bounds PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_kpm.py::test_operator_user PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_kpm.py::test_kwant_syst PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_kpm.py::test_kwant_op PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_kpm.py::test_kwant_op_current PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_kpm.py::test_kwant_op_integrate PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_kpm.py::test_increase_num_moments PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_kpm.py::test_increase_num_moments_op PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_kpm.py::test_increase_num_vectors PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_kpm.py::test_invalid_input PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_kpm.py::test_check_convergence_decreasing_values PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_kpm.py::test_convergence_custom_vector_factory PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_kpm.py::test_call_no_argument PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_kpm.py::test_call PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_kpm.py::test_integrate PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_kpm.py::test_increase_energy_resolution PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_kpm.py::test_rescale PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_lattice.py::test_closest PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_lattice.py::test_general PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_lattice.py::test_neighbors PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_lattice.py::test_shape PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_lattice.py::test_wire PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_lattice.py::test_translational_symmetry PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_lattice.py::test_translational_symmetry_reversed PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_lattice.py::test_monatomic_lattice PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_lattice.py::test_lattice_constraints[1-None] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_lattice.py::test_lattice_constraints[prim_vecs1-None] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_lattice.py::test_lattice_constraints[prim_vecs2-basis2] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_lattice.py::test_lattice_constraints[prim_vecs3-None] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_lattice.py::test_lattice_constraints[prim_vecs4-basis4] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_lattice.py::test_lattice_constraints[prim_vecs5-None] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_lattice.py::test_lattice_constraints[prim_vecs6-basis6] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_lattice.py::test_norbs PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_lattice.py::test_symmetry_act PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_lattice.py::test_symmetry_has_subgroup PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_operator.py::test_operator_construction PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_operator.py::test_opservables_finite PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_operator.py::test_opservables_infinite PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_operator.py::test_opservables_scattering FAILED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_operator.py::test_opservables_spin FAILED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_operator.py::test_opservables_gauged FAILED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_operator.py::test_tocoo PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_operator.py::test_arg_passing[Density] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_operator.py::test_arg_passing[Current] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_operator.py::test_arg_passing[Source] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_operator.py::test_pickling[Density] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_operator.py::test_pickling[Current] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_operator.py::test_pickling[Source] PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_plotter.py::test_matplotlib_backend_unset PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_plotter.py::test_importable_without_matplotlib PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_plotter.py::test_plot PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_plotter.py::test_plot_more_site_families_than_colors PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_plotter.py::test_map PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_plotter.py::test_mask_interpolate PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_plotter.py::test_bands PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_plotter.py::test_spectrum PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_plotter.py::test_density_interpolation PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_plotter.py::test_current_interpolation FAILED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_plotter.py::test_current PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_qsymm.py::test_honeycomb PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_qsymm.py::test_get_builder_symmetries PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_qsymm.py::test_higher_dim PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_qsymm.py::test_graphene_to_kwant PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_qsymm.py::test_wraparound_convention PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_qsymm.py::test_inverse_transform PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_qsymm.py::test_consistency_kwant PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_qsymm.py::test_find_builder_discrete_symmetries PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_qsymm.py::test_real_space_basis PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_qsymm.py::test_find_cons_law PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_qsymm.py::test_basis_ordering SKIPPED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_rmt.py::test_gaussian_symmetries PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_rmt.py::test_gaussian_distributions PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_rmt.py::test_circular PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_system.py::test_hamiltonian_submatrix PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_system.py::test_pickling PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_wraparound.py::test_consistence_with_bands PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_wraparound.py::test_opposite_hoppings PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_wraparound.py::test_value_types PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_wraparound.py::test_signatures PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_wraparound.py::test_symmetry PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_wraparound.py::test_plot_2d_bands PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_wraparound.py::test_fd_mismatch PASSED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_wraparound.py::test_args_params_equivalence PASSED ======================================== FAILURES ======================================== ___________________________________ test_lu_with_dense ___________________________________ def test_lu_with_dense(): def _test_lu_with_dense(dtype): rand = _Random() a = rand.randmat(5, 5, dtype) bmat = rand.randmat(5, 5, dtype) bvec = rand.randvec(5, dtype) ctx = MUMPSContext() ctx.factor(sp.coo_matrix(a)) xvec = ctx.solve(bvec) xmat = ctx.solve(bmat) assert_array_almost_equal(dtype, np.dot(a, xmat), bmat) assert_array_almost_equal(dtype, np.dot(a, xvec), bvec) # now "sparse" right hand side xvec = ctx.solve(sp.csc_matrix(bvec.reshape(5,1))) xmat = ctx.solve(sp.csc_matrix(bmat)) assert_array_almost_equal(dtype, np.dot(a, xmat), bmat) assert_array_almost_equal(dtype, np.dot(a, xvec), bvec.reshape(5,1)) > _test_lu_with_dense(np.complex128) miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/linalg/tests/test_mumps.py:51: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/linalg/tests/test_mumps.py:39: in _test_lu_with_dense assert_array_almost_equal(dtype, np.dot(a, xmat), bmat) miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/linalg/tests/_test_utils.py:84: in assert_array_almost_equal np.testing.assert_array_almost_equal(a, b, decimal=prec) miniconda3/envs/myKwant/lib/python3.11/contextlib.py:81: in inner return func(*args, **kwds) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ args = (.compare at 0x13985b420>, array([[ 12.42977301 -8.30719118j, 4.04292476... -0.81970215+0.88668823j, 0.4175415 -0.03378296j, 0.11669922-0.78140259j, -0.237854 -0.24679565j]])) kwds = {'err_msg': '', 'header': 'Arrays are not almost equal to 10 decimals', 'precision': 10, 'verbose': True} @wraps(func) def inner(*args, **kwds): with self._recreate_cm(): > return func(*args, **kwds) E AssertionError: E Arrays are not almost equal to 10 decimals E E Mismatched elements: 25 / 25 (100%) E Max absolute difference: 27.89062542 E Max relative difference: 69.50185495 E x: array([[ 12.4297730119 -8.3071911783j, 4.0429247583 +7.3582662417j, E -10.486799187 +1.6073372914j, 0.211013518 -21.2981470995j, E 1.6189135279 -7.3005982039j],... E y: array([[-0.4277954102-0.0578308105j, -0.7501220703+0.9074401855j, E -0.032409668 +0.4986877441j, -0.0402832031+0.5752868652j, E -0.2893676758-0.7533874512j],... miniconda3/envs/myKwant/lib/python3.11/contextlib.py:81: AssertionError _____________________________ test_uniform_magnetic_field[0] _____________________________ system_and_gauge = (, ) B = 0 @pytest.mark.parametrize('B',[0, 0.1, lambda r: 0.1 * np.exp(-r[1]**2)]) def test_uniform_magnetic_field(system_and_gauge, B): syst, gauge = system_and_gauge peierls, peierls_left, peierls_right = gauge(B, B, B) params = dict(peierls=peierls, peierls_left=peierls_left, peierls_right=peierls_right) s = kwant.smatrix(syst, energy=0.6, params=params) t = s.submatrix(1, 0) assert t.shape > (0, 0) # sanity check > assert np.allclose(np.abs(t)**2, np.eye(*t.shape)) E AssertionError: assert False E + where False = ((array([[7.07107482e-01, 1.67600362e-15],\n [8.75376513e-15, 7.71350363e-01]]) ** 2), array([[1., 0.],\n [0., 1.]])) E + where = np.allclose E + and array([[7.07107482e-01, 1.67600362e-15],\n [8.75376513e-15, 7.71350363e-01]]) = (array([[ 5.00000496e-01+5.00000496e-01j, 1.62965702e-15+3.91415537e-16j],\n [-8.73860518e-15+5.14959524e-16j, 5.45427072e-01+5.45427072e-01j]])) E + where = np.abs E + and array([[1., 0.],\n [0., 1.]]) = (*(2, 2)) E + where = np.eye E + and (2, 2) = array([[ 5.00000496e-01+5.00000496e-01j, 1.62965702e-15+3.91415537e-16j],\n [-8.73860518e-15+5.14959524e-16j, 5.45427072e-01+5.45427072e-01j]]).shape miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py:521: AssertionError ____________________________ test_uniform_magnetic_field[0.1] ____________________________ system_and_gauge = (, ) B = 0.1 @pytest.mark.parametrize('B',[0, 0.1, lambda r: 0.1 * np.exp(-r[1]**2)]) def test_uniform_magnetic_field(system_and_gauge, B): syst, gauge = system_and_gauge peierls, peierls_left, peierls_right = gauge(B, B, B) params = dict(peierls=peierls, peierls_left=peierls_left, peierls_right=peierls_right) s = kwant.smatrix(syst, energy=0.6, params=params) t = s.submatrix(1, 0) assert t.shape > (0, 0) # sanity check > assert np.allclose(np.abs(t)**2, np.eye(*t.shape)) E AssertionError: assert False E + where False = ((array([[0.45430061]]) ** 2), array([[1.]])) E + where = np.allclose E + and array([[0.45430061]]) = (array([[-0.44456255+0.09355846j]])) E + where = np.abs E + and array([[1.]]) = (*(1, 1)) E + where = np.eye E + and (1, 1) = array([[-0.44456255+0.09355846j]]).shape miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py:521: AssertionError _________________________ test_uniform_magnetic_field[] __________________________ system_and_gauge = (, ) B = at 0x12e36e200> @pytest.mark.parametrize('B',[0, 0.1, lambda r: 0.1 * np.exp(-r[1]**2)]) def test_uniform_magnetic_field(system_and_gauge, B): syst, gauge = system_and_gauge peierls, peierls_left, peierls_right = gauge(B, B, B) params = dict(peierls=peierls, peierls_left=peierls_left, peierls_right=peierls_right) s = kwant.smatrix(syst, energy=0.6, params=params) t = s.submatrix(1, 0) assert t.shape > (0, 0) # sanity check > assert np.allclose(np.abs(t)**2, np.eye(*t.shape)) E AssertionError: assert False E + where False = ((array([[1.25605935, 0.06054725],\n [0.05009391, 0.78693486]]) ** 2), array([[1., 0.],\n [0., 1.]])) E + where = np.allclose E + and array([[1.25605935, 0.06054725],\n [0.05009391, 0.78693486]]) = (array([[-5.88108623e-01+1.10987086j, 1.42024774e-04+0.06054708j],\n [-1.92849992e-02-0.04623298j, 7.53445077e-01+0.22712771j]])) E + where = np.abs E + and array([[1., 0.],\n [0., 1.]]) = (*(2, 2)) E + where = np.eye E + and (2, 2) = array([[-5.88108623e-01+1.10987086j, 1.42024774e-04+0.06054708j],\n [-1.92849992e-02-0.04623298j, 7.53445077e-01+0.22712771j]]).shape miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py:521: AssertionError ____________________________________ test_phase_sign _____________________________________ system_and_gauge = (, ) def test_phase_sign(system_and_gauge): syst, gauge = system_and_gauge peierls, peierls_left, peierls_right = gauge(0.1, 0.1, 0.1) params = dict(peierls=peierls, peierls_left=peierls_left, peierls_right=peierls_right) cut = [(square_lattice(1, j), square_lattice(0, j)) for j in range(10)] J = kwant.operator.Current(syst, where=cut) J = J.bind(params=params) psi = kwant.wave_function(syst, energy=0.6, params=params)(0)[0] # Electrons incident from the left travel along the *top* # edge of the Hall bar in the presence of a magnetic field # out of the plane j = J(psi) j_bottom = sum(j[0:5]) j_top = sum(j[5:10]) > assert np.isclose(j_top + j_bottom, 1) # sanity check E assert False E + where False = ((0.08508703550761182 + -0.011234152147354078), 1) E + where = np.isclose miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py:546: AssertionError ____________________________________ test_twoterminal ____________________________________ def test_twoterminal(): """Shot noise in a two-terminal conductor""" fsyst = twoterminal_system().finalized() sol = kwant.smatrix(fsyst) t = sol.submatrix(1, 0) Tn = np.linalg.eigvalsh(np.dot(t, t.conj().T)) noise_should_be = np.sum(Tn * (1 - Tn)) > assert_almost_equal(noise_should_be, two_terminal_shotnoise(sol)) miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_noise.py:54: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ args = (-25.804453623104934, -43.753131308304056), kwds = {} @wraps(func) def inner(*args, **kwds): with self._recreate_cm(): > return func(*args, **kwds) E AssertionError: E Arrays are not almost equal to 7 decimals E ACTUAL: -25.804453623104934 E DESIRED: -43.753131308304056 miniconda3/envs/myKwant/lib/python3.11/contextlib.py:81: AssertionError ______________________________________ test_output _______________________________________ actual = array([[ 1.20199953-5.74417904e-18j, -0.93111313-1.04373214e+00j, 0.43819726+9.60661296e-01j], [-0.931...6805354e-01j], [ 0.43819726-9.60661296e-01j, -1.02864452+8.36805354e-01j, 1.84424823-1.51362924e-17j]]) desired = array([[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]]), decimal = 7 err_msg = '', verbose = True @np._no_nep50_warning() def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=True): """ Raises an AssertionError if two items are not equal up to desired precision. .. note:: It is recommended to use one of `assert_allclose`, `assert_array_almost_equal_nulp` or `assert_array_max_ulp` instead of this function for more consistent floating point comparisons. The test verifies that the elements of `actual` and `desired` satisfy. ``abs(desired-actual) < float64(1.5 * 10**(-decimal))`` That is a looser test than originally documented, but agrees with what the actual implementation in `assert_array_almost_equal` did up to rounding vagaries. An exception is raised at conflicting values. For ndarrays this delegates to assert_array_almost_equal Parameters ---------- actual : array_like The object to check. desired : array_like The expected object. decimal : int, optional Desired precision, default is 7. err_msg : str, optional The error message to be printed in case of failure. verbose : bool, optional If True, the conflicting values are appended to the error message. Raises ------ AssertionError If actual and desired are not equal up to specified precision. See Also -------- assert_allclose: Compare two array_like objects for equality with desired relative and/or absolute precision. assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal Examples -------- >>> from numpy.testing import assert_almost_equal >>> assert_almost_equal(2.3333333333333, 2.33333334) >>> assert_almost_equal(2.3333333333333, 2.33333334, decimal=10) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 10 decimals ACTUAL: 2.3333333333333 DESIRED: 2.33333334 >>> assert_almost_equal(np.array([1.0,2.3333333333333]), ... np.array([1.0,2.33333334]), decimal=9) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 9 decimals Mismatched elements: 1 / 2 (50%) Max absolute difference: 6.66669964e-09 Max relative difference: 2.85715698e-09 x: array([1. , 2.333333333]) y: array([1. , 2.33333334]) """ __tracebackhide__ = True # Hide traceback for py.test from numpy.core import ndarray from numpy.lib import iscomplexobj, real, imag # Handle complex numbers: separate into real/imag to handle # nan/inf/negative zero correctly # XXX: catch ValueError for subclasses of ndarray where iscomplex fail try: usecomplex = iscomplexobj(actual) or iscomplexobj(desired) except ValueError: usecomplex = False def _build_err_msg(): header = ('Arrays are not almost equal to %d decimals' % decimal) return build_err_msg([actual, desired], err_msg, verbose=verbose, header=header) if usecomplex: if iscomplexobj(actual): actualr = real(actual) actuali = imag(actual) else: actualr = actual actuali = 0 if iscomplexobj(desired): desiredr = real(desired) desiredi = imag(desired) else: desiredr = desired desiredi = 0 try: > assert_almost_equal(actualr, desiredr, decimal=decimal) miniconda3/envs/myKwant/lib/python3.11/site-packages/numpy/testing/_private/utils.py:581: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ args = (array([[ 1.20199953, -0.93111313, 0.43819726], [-0.93111313, 2.13649085, -1.02864452], [ 0.43819726, -1.02864452, 1.84424823]]), array([[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]])) kwds = {'decimal': 7} @wraps(func) def inner(*args, **kwds): with self._recreate_cm(): > return func(*args, **kwds) miniconda3/envs/myKwant/lib/python3.11/contextlib.py:81: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ actual = array([[ 1.20199953, -0.93111313, 0.43819726], [-0.93111313, 2.13649085, -1.02864452], [ 0.43819726, -1.02864452, 1.84424823]]) desired = array([[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]]), decimal = 7 err_msg = '', verbose = True @np._no_nep50_warning() def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=True): """ Raises an AssertionError if two items are not equal up to desired precision. .. note:: It is recommended to use one of `assert_allclose`, `assert_array_almost_equal_nulp` or `assert_array_max_ulp` instead of this function for more consistent floating point comparisons. The test verifies that the elements of `actual` and `desired` satisfy. ``abs(desired-actual) < float64(1.5 * 10**(-decimal))`` That is a looser test than originally documented, but agrees with what the actual implementation in `assert_array_almost_equal` did up to rounding vagaries. An exception is raised at conflicting values. For ndarrays this delegates to assert_array_almost_equal Parameters ---------- actual : array_like The object to check. desired : array_like The expected object. decimal : int, optional Desired precision, default is 7. err_msg : str, optional The error message to be printed in case of failure. verbose : bool, optional If True, the conflicting values are appended to the error message. Raises ------ AssertionError If actual and desired are not equal up to specified precision. See Also -------- assert_allclose: Compare two array_like objects for equality with desired relative and/or absolute precision. assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal Examples -------- >>> from numpy.testing import assert_almost_equal >>> assert_almost_equal(2.3333333333333, 2.33333334) >>> assert_almost_equal(2.3333333333333, 2.33333334, decimal=10) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 10 decimals ACTUAL: 2.3333333333333 DESIRED: 2.33333334 >>> assert_almost_equal(np.array([1.0,2.3333333333333]), ... np.array([1.0,2.33333334]), decimal=9) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 9 decimals Mismatched elements: 1 / 2 (50%) Max absolute difference: 6.66669964e-09 Max relative difference: 2.85715698e-09 x: array([1. , 2.333333333]) y: array([1. , 2.33333334]) """ __tracebackhide__ = True # Hide traceback for py.test from numpy.core import ndarray from numpy.lib import iscomplexobj, real, imag # Handle complex numbers: separate into real/imag to handle # nan/inf/negative zero correctly # XXX: catch ValueError for subclasses of ndarray where iscomplex fail try: usecomplex = iscomplexobj(actual) or iscomplexobj(desired) except ValueError: usecomplex = False def _build_err_msg(): header = ('Arrays are not almost equal to %d decimals' % decimal) return build_err_msg([actual, desired], err_msg, verbose=verbose, header=header) if usecomplex: if iscomplexobj(actual): actualr = real(actual) actuali = imag(actual) else: actualr = actual actuali = 0 if iscomplexobj(desired): desiredr = real(desired) desiredi = imag(desired) else: desiredr = desired desiredi = 0 try: assert_almost_equal(actualr, desiredr, decimal=decimal) assert_almost_equal(actuali, desiredi, decimal=decimal) except AssertionError: raise AssertionError(_build_err_msg()) if isinstance(actual, (ndarray, tuple, list)) \ or isinstance(desired, (ndarray, tuple, list)): > return assert_array_almost_equal(actual, desired, decimal, err_msg) miniconda3/envs/myKwant/lib/python3.11/site-packages/numpy/testing/_private/utils.py:588: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ args = (array([[ 1.20199953, -0.93111313, 0.43819726], [-0.93111313, 2.13649085, -1.02864452], [ 0.43819726, -1.02864452, 1.84424823]]), array([[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]]), 7, '') kwds = {} @wraps(func) def inner(*args, **kwds): with self._recreate_cm(): > return func(*args, **kwds) miniconda3/envs/myKwant/lib/python3.11/contextlib.py:81: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ x = array([[ 1.20199953, -0.93111313, 0.43819726], [-0.93111313, 2.13649085, -1.02864452], [ 0.43819726, -1.02864452, 1.84424823]]) y = array([[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]]), decimal = 7 err_msg = '', verbose = True @np._no_nep50_warning() def assert_array_almost_equal(x, y, decimal=6, err_msg='', verbose=True): """ Raises an AssertionError if two objects are not equal up to desired precision. .. note:: It is recommended to use one of `assert_allclose`, `assert_array_almost_equal_nulp` or `assert_array_max_ulp` instead of this function for more consistent floating point comparisons. The test verifies identical shapes and that the elements of ``actual`` and ``desired`` satisfy. ``abs(desired-actual) < 1.5 * 10**(-decimal)`` That is a looser test than originally documented, but agrees with what the actual implementation did up to rounding vagaries. An exception is raised at shape mismatch or conflicting values. In contrast to the standard usage in numpy, NaNs are compared like numbers, no assertion is raised if both objects have NaNs in the same positions. Parameters ---------- x : array_like The actual object to check. y : array_like The desired, expected object. decimal : int, optional Desired precision, default is 6. err_msg : str, optional The error message to be printed in case of failure. verbose : bool, optional If True, the conflicting values are appended to the error message. Raises ------ AssertionError If actual and desired are not equal up to specified precision. See Also -------- assert_allclose: Compare two array_like objects for equality with desired relative and/or absolute precision. assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal Examples -------- the first assert does not raise an exception >>> np.testing.assert_array_almost_equal([1.0,2.333,np.nan], ... [1.0,2.333,np.nan]) >>> np.testing.assert_array_almost_equal([1.0,2.33333,np.nan], ... [1.0,2.33339,np.nan], decimal=5) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 5 decimals Mismatched elements: 1 / 3 (33.3%) Max absolute difference: 6.e-05 Max relative difference: 2.57136612e-05 x: array([1. , 2.33333, nan]) y: array([1. , 2.33339, nan]) >>> np.testing.assert_array_almost_equal([1.0,2.33333,np.nan], ... [1.0,2.33333, 5], decimal=5) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 5 decimals x and y nan location mismatch: x: array([1. , 2.33333, nan]) y: array([1. , 2.33333, 5. ]) """ __tracebackhide__ = True # Hide traceback for py.test from numpy.core import number, float_, result_type, array from numpy.core.numerictypes import issubdtype from numpy.core.fromnumeric import any as npany def compare(x, y): try: if npany(gisinf(x)) or npany( gisinf(y)): xinfid = gisinf(x) yinfid = gisinf(y) if not (xinfid == yinfid).all(): return False # if one item, x and y is +- inf if x.size == y.size == 1: return x == y x = x[~xinfid] y = y[~yinfid] except (TypeError, NotImplementedError): pass # make sure y is an inexact type to avoid abs(MIN_INT); will cause # casting of x later. dtype = result_type(y, 1.) y = np.asanyarray(y, dtype) z = abs(x - y) if not issubdtype(z.dtype, number): z = z.astype(float_) # handle object arrays return z < 1.5 * 10.0**(-decimal) > assert_array_compare(compare, x, y, err_msg=err_msg, verbose=verbose, header=('Arrays are not almost equal to %d decimals' % decimal), precision=decimal) miniconda3/envs/myKwant/lib/python3.11/site-packages/numpy/testing/_private/utils.py:1099: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ args = (.compare at 0x139a3ba60>, array([[ 1.20199953, -0.93111313, 0.43819726],...52], [ 0.43819726, -1.02864452, 1.84424823]]), array([[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]])) kwds = {'err_msg': '', 'header': 'Arrays are not almost equal to 7 decimals', 'precision': 7, 'verbose': True} @wraps(func) def inner(*args, **kwds): with self._recreate_cm(): > return func(*args, **kwds) miniconda3/envs/myKwant/lib/python3.11/contextlib.py:81: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ comparison = .compare at 0x139a3ba60> x = array([ 1.20199953, -0.93111313, 0.43819726, -0.93111313, 2.13649085, -1.02864452, 0.43819726, -1.02864452, 1.84424823]) y = array([1., 0., 0., 0., 1., 0., 0., 0., 1.]) err_msg = '\nMismatched elements: 9 / 9 (100%)\nMax absolute difference: 1.13649085\nMax relative difference: 1.13649085' verbose = True, header = 'Arrays are not almost equal to 7 decimals', precision = 7 equal_nan = True, equal_inf = True @np._no_nep50_warning() def assert_array_compare(comparison, x, y, err_msg='', verbose=True, header='', precision=6, equal_nan=True, equal_inf=True, *, strict=False): __tracebackhide__ = True # Hide traceback for py.test from numpy.core import array, array2string, isnan, inf, bool_, errstate, all, max, object_ x = np.asanyarray(x) y = np.asanyarray(y) # original array for output formatting ox, oy = x, y def isnumber(x): return x.dtype.char in '?bhilqpBHILQPefdgFDG' def istime(x): return x.dtype.char in "Mm" def func_assert_same_pos(x, y, func=isnan, hasval='nan'): """Handling nan/inf. Combine results of running func on x and y, checking that they are True at the same locations. """ __tracebackhide__ = True # Hide traceback for py.test x_id = func(x) y_id = func(y) # We include work-arounds here to handle three types of slightly # pathological ndarray subclasses: # (1) all() on `masked` array scalars can return masked arrays, so we # use != True # (2) __eq__ on some ndarray subclasses returns Python booleans # instead of element-wise comparisons, so we cast to bool_() and # use isinstance(..., bool) checks # (3) subclasses with bare-bones __array_function__ implementations may # not implement np.all(), so favor using the .all() method # We are not committed to supporting such subclasses, but it's nice to # support them if possible. if bool_(x_id == y_id).all() != True: msg = build_err_msg([x, y], err_msg + '\nx and y %s location mismatch:' % (hasval), verbose=verbose, header=header, names=('x', 'y'), precision=precision) raise AssertionError(msg) # If there is a scalar, then here we know the array has the same # flag as it everywhere, so we should return the scalar flag. if isinstance(x_id, bool) or x_id.ndim == 0: return bool_(x_id) elif isinstance(y_id, bool) or y_id.ndim == 0: return bool_(y_id) else: return y_id try: if strict: cond = x.shape == y.shape and x.dtype == y.dtype else: cond = (x.shape == () or y.shape == ()) or x.shape == y.shape if not cond: if x.shape != y.shape: reason = f'\n(shapes {x.shape}, {y.shape} mismatch)' else: reason = f'\n(dtypes {x.dtype}, {y.dtype} mismatch)' msg = build_err_msg([x, y], err_msg + reason, verbose=verbose, header=header, names=('x', 'y'), precision=precision) raise AssertionError(msg) flagged = bool_(False) if isnumber(x) and isnumber(y): if equal_nan: flagged = func_assert_same_pos(x, y, func=isnan, hasval='nan') if equal_inf: flagged |= func_assert_same_pos(x, y, func=lambda xy: xy == +inf, hasval='+inf') flagged |= func_assert_same_pos(x, y, func=lambda xy: xy == -inf, hasval='-inf') elif istime(x) and istime(y): # If one is datetime64 and the other timedelta64 there is no point if equal_nan and x.dtype.type == y.dtype.type: flagged = func_assert_same_pos(x, y, func=isnat, hasval="NaT") if flagged.ndim > 0: x, y = x[~flagged], y[~flagged] # Only do the comparison if actual values are left if x.size == 0: return elif flagged: # no sense doing comparison if everything is flagged. return val = comparison(x, y) if isinstance(val, bool): cond = val reduced = array([val]) else: reduced = val.ravel() cond = reduced.all() # The below comparison is a hack to ensure that fully masked # results, for which val.ravel().all() returns np.ma.masked, # do not trigger a failure (np.ma.masked != True evaluates as # np.ma.masked, which is falsy). if cond != True: n_mismatch = reduced.size - reduced.sum(dtype=intp) n_elements = flagged.size if flagged.ndim != 0 else reduced.size percent_mismatch = 100 * n_mismatch / n_elements remarks = [ 'Mismatched elements: {} / {} ({:.3g}%)'.format( n_mismatch, n_elements, percent_mismatch)] with errstate(all='ignore'): # ignore errors for non-numeric types with contextlib.suppress(TypeError): error = abs(x - y) if np.issubdtype(x.dtype, np.unsignedinteger): error2 = abs(y - x) np.minimum(error, error2, out=error) max_abs_error = max(error) if getattr(error, 'dtype', object_) == object_: remarks.append('Max absolute difference: ' + str(max_abs_error)) else: remarks.append('Max absolute difference: ' + array2string(max_abs_error)) # note: this definition of relative error matches that one # used by assert_allclose (found in np.isclose) # Filter values where the divisor would be zero nonzero = bool_(y != 0) if all(~nonzero): max_rel_error = array(inf) else: max_rel_error = max(error[nonzero] / abs(y[nonzero])) if getattr(error, 'dtype', object_) == object_: remarks.append('Max relative difference: ' + str(max_rel_error)) else: remarks.append('Max relative difference: ' + array2string(max_rel_error)) err_msg += '\n' + '\n'.join(remarks) msg = build_err_msg([ox, oy], err_msg, verbose=verbose, header=header, names=('x', 'y'), precision=precision) > raise AssertionError(msg) E AssertionError: E Arrays are not almost equal to 7 decimals E E Mismatched elements: 9 / 9 (100%) E Max absolute difference: 1.13649085 E Max relative difference: 1.13649085 E x: array([[ 1.2019995, -0.9311131, 0.4381973], E [-0.9311131, 2.1364909, -1.0286445], E [ 0.4381973, -1.0286445, 1.8442482]]) E y: array([[1., 0., 0.], E [0., 1., 0.], E [0., 0., 1.]]) miniconda3/envs/myKwant/lib/python3.11/site-packages/numpy/testing/_private/utils.py:862: AssertionError During handling of the above exception, another exception occurred: def test_output(): for opts in opt_list: reset_options() options(**opts) > _test_sparse.test_output(smatrix) miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/test_mumps.py:32: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/_test_sparse.py:72: in test_output assert_almost_equal(np.dot(s.T.conj(), s), _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ args = (array([[ 1.20199953-5.74417904e-18j, -0.93111313-1.04373214e+00j, 0.43819726+9.60661296e-01j], [-0.93...36805354e-01j, 1.84424823-1.51362924e-17j]]), array([[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]])) kwds = {} @wraps(func) def inner(*args, **kwds): with self._recreate_cm(): > return func(*args, **kwds) E AssertionError: E Arrays are not almost equal to 7 decimals E ACTUAL: array([[ 1.20199953-5.74417904e-18j, -0.93111313-1.04373214e+00j, E 0.43819726+9.60661296e-01j], E [-0.93111313+1.04373214e+00j, 2.13649085+1.08564286e-17j,... E DESIRED: array([[1., 0., 0.], E [0., 1., 0.], E [0., 0., 1.]]) miniconda3/envs/myKwant/lib/python3.11/contextlib.py:81: AssertionError _____________________________________ test_one_lead ______________________________________ actual = array([[ 1.61723997-1.27997928e-18j, -1.50673361-1.07088697e+00j], [-1.50673361+1.07088697e+00j, 3.62336746+4.41835134e-18j]]) desired = array([[1., 0.], [0., 1.]]), decimal = 7, err_msg = '', verbose = True @np._no_nep50_warning() def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=True): """ Raises an AssertionError if two items are not equal up to desired precision. .. note:: It is recommended to use one of `assert_allclose`, `assert_array_almost_equal_nulp` or `assert_array_max_ulp` instead of this function for more consistent floating point comparisons. The test verifies that the elements of `actual` and `desired` satisfy. ``abs(desired-actual) < float64(1.5 * 10**(-decimal))`` That is a looser test than originally documented, but agrees with what the actual implementation in `assert_array_almost_equal` did up to rounding vagaries. An exception is raised at conflicting values. For ndarrays this delegates to assert_array_almost_equal Parameters ---------- actual : array_like The object to check. desired : array_like The expected object. decimal : int, optional Desired precision, default is 7. err_msg : str, optional The error message to be printed in case of failure. verbose : bool, optional If True, the conflicting values are appended to the error message. Raises ------ AssertionError If actual and desired are not equal up to specified precision. See Also -------- assert_allclose: Compare two array_like objects for equality with desired relative and/or absolute precision. assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal Examples -------- >>> from numpy.testing import assert_almost_equal >>> assert_almost_equal(2.3333333333333, 2.33333334) >>> assert_almost_equal(2.3333333333333, 2.33333334, decimal=10) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 10 decimals ACTUAL: 2.3333333333333 DESIRED: 2.33333334 >>> assert_almost_equal(np.array([1.0,2.3333333333333]), ... np.array([1.0,2.33333334]), decimal=9) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 9 decimals Mismatched elements: 1 / 2 (50%) Max absolute difference: 6.66669964e-09 Max relative difference: 2.85715698e-09 x: array([1. , 2.333333333]) y: array([1. , 2.33333334]) """ __tracebackhide__ = True # Hide traceback for py.test from numpy.core import ndarray from numpy.lib import iscomplexobj, real, imag # Handle complex numbers: separate into real/imag to handle # nan/inf/negative zero correctly # XXX: catch ValueError for subclasses of ndarray where iscomplex fail try: usecomplex = iscomplexobj(actual) or iscomplexobj(desired) except ValueError: usecomplex = False def _build_err_msg(): header = ('Arrays are not almost equal to %d decimals' % decimal) return build_err_msg([actual, desired], err_msg, verbose=verbose, header=header) if usecomplex: if iscomplexobj(actual): actualr = real(actual) actuali = imag(actual) else: actualr = actual actuali = 0 if iscomplexobj(desired): desiredr = real(desired) desiredi = imag(desired) else: desiredr = desired desiredi = 0 try: > assert_almost_equal(actualr, desiredr, decimal=decimal) miniconda3/envs/myKwant/lib/python3.11/site-packages/numpy/testing/_private/utils.py:581: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ args = (array([[ 1.61723997, -1.50673361], [-1.50673361, 3.62336746]]), array([[1., 0.], [0., 1.]])) kwds = {'decimal': 7} @wraps(func) def inner(*args, **kwds): with self._recreate_cm(): > return func(*args, **kwds) miniconda3/envs/myKwant/lib/python3.11/contextlib.py:81: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ actual = array([[ 1.61723997, -1.50673361], [-1.50673361, 3.62336746]]) desired = array([[1., 0.], [0., 1.]]), decimal = 7, err_msg = '', verbose = True @np._no_nep50_warning() def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=True): """ Raises an AssertionError if two items are not equal up to desired precision. .. note:: It is recommended to use one of `assert_allclose`, `assert_array_almost_equal_nulp` or `assert_array_max_ulp` instead of this function for more consistent floating point comparisons. The test verifies that the elements of `actual` and `desired` satisfy. ``abs(desired-actual) < float64(1.5 * 10**(-decimal))`` That is a looser test than originally documented, but agrees with what the actual implementation in `assert_array_almost_equal` did up to rounding vagaries. An exception is raised at conflicting values. For ndarrays this delegates to assert_array_almost_equal Parameters ---------- actual : array_like The object to check. desired : array_like The expected object. decimal : int, optional Desired precision, default is 7. err_msg : str, optional The error message to be printed in case of failure. verbose : bool, optional If True, the conflicting values are appended to the error message. Raises ------ AssertionError If actual and desired are not equal up to specified precision. See Also -------- assert_allclose: Compare two array_like objects for equality with desired relative and/or absolute precision. assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal Examples -------- >>> from numpy.testing import assert_almost_equal >>> assert_almost_equal(2.3333333333333, 2.33333334) >>> assert_almost_equal(2.3333333333333, 2.33333334, decimal=10) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 10 decimals ACTUAL: 2.3333333333333 DESIRED: 2.33333334 >>> assert_almost_equal(np.array([1.0,2.3333333333333]), ... np.array([1.0,2.33333334]), decimal=9) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 9 decimals Mismatched elements: 1 / 2 (50%) Max absolute difference: 6.66669964e-09 Max relative difference: 2.85715698e-09 x: array([1. , 2.333333333]) y: array([1. , 2.33333334]) """ __tracebackhide__ = True # Hide traceback for py.test from numpy.core import ndarray from numpy.lib import iscomplexobj, real, imag # Handle complex numbers: separate into real/imag to handle # nan/inf/negative zero correctly # XXX: catch ValueError for subclasses of ndarray where iscomplex fail try: usecomplex = iscomplexobj(actual) or iscomplexobj(desired) except ValueError: usecomplex = False def _build_err_msg(): header = ('Arrays are not almost equal to %d decimals' % decimal) return build_err_msg([actual, desired], err_msg, verbose=verbose, header=header) if usecomplex: if iscomplexobj(actual): actualr = real(actual) actuali = imag(actual) else: actualr = actual actuali = 0 if iscomplexobj(desired): desiredr = real(desired) desiredi = imag(desired) else: desiredr = desired desiredi = 0 try: assert_almost_equal(actualr, desiredr, decimal=decimal) assert_almost_equal(actuali, desiredi, decimal=decimal) except AssertionError: raise AssertionError(_build_err_msg()) if isinstance(actual, (ndarray, tuple, list)) \ or isinstance(desired, (ndarray, tuple, list)): > return assert_array_almost_equal(actual, desired, decimal, err_msg) miniconda3/envs/myKwant/lib/python3.11/site-packages/numpy/testing/_private/utils.py:588: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ args = (array([[ 1.61723997, -1.50673361], [-1.50673361, 3.62336746]]), array([[1., 0.], [0., 1.]]), 7, '') kwds = {} @wraps(func) def inner(*args, **kwds): with self._recreate_cm(): > return func(*args, **kwds) miniconda3/envs/myKwant/lib/python3.11/contextlib.py:81: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ x = array([[ 1.61723997, -1.50673361], [-1.50673361, 3.62336746]]) y = array([[1., 0.], [0., 1.]]), decimal = 7, err_msg = '', verbose = True @np._no_nep50_warning() def assert_array_almost_equal(x, y, decimal=6, err_msg='', verbose=True): """ Raises an AssertionError if two objects are not equal up to desired precision. .. note:: It is recommended to use one of `assert_allclose`, `assert_array_almost_equal_nulp` or `assert_array_max_ulp` instead of this function for more consistent floating point comparisons. The test verifies identical shapes and that the elements of ``actual`` and ``desired`` satisfy. ``abs(desired-actual) < 1.5 * 10**(-decimal)`` That is a looser test than originally documented, but agrees with what the actual implementation did up to rounding vagaries. An exception is raised at shape mismatch or conflicting values. In contrast to the standard usage in numpy, NaNs are compared like numbers, no assertion is raised if both objects have NaNs in the same positions. Parameters ---------- x : array_like The actual object to check. y : array_like The desired, expected object. decimal : int, optional Desired precision, default is 6. err_msg : str, optional The error message to be printed in case of failure. verbose : bool, optional If True, the conflicting values are appended to the error message. Raises ------ AssertionError If actual and desired are not equal up to specified precision. See Also -------- assert_allclose: Compare two array_like objects for equality with desired relative and/or absolute precision. assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal Examples -------- the first assert does not raise an exception >>> np.testing.assert_array_almost_equal([1.0,2.333,np.nan], ... [1.0,2.333,np.nan]) >>> np.testing.assert_array_almost_equal([1.0,2.33333,np.nan], ... [1.0,2.33339,np.nan], decimal=5) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 5 decimals Mismatched elements: 1 / 3 (33.3%) Max absolute difference: 6.e-05 Max relative difference: 2.57136612e-05 x: array([1. , 2.33333, nan]) y: array([1. , 2.33339, nan]) >>> np.testing.assert_array_almost_equal([1.0,2.33333,np.nan], ... [1.0,2.33333, 5], decimal=5) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 5 decimals x and y nan location mismatch: x: array([1. , 2.33333, nan]) y: array([1. , 2.33333, 5. ]) """ __tracebackhide__ = True # Hide traceback for py.test from numpy.core import number, float_, result_type, array from numpy.core.numerictypes import issubdtype from numpy.core.fromnumeric import any as npany def compare(x, y): try: if npany(gisinf(x)) or npany( gisinf(y)): xinfid = gisinf(x) yinfid = gisinf(y) if not (xinfid == yinfid).all(): return False # if one item, x and y is +- inf if x.size == y.size == 1: return x == y x = x[~xinfid] y = y[~yinfid] except (TypeError, NotImplementedError): pass # make sure y is an inexact type to avoid abs(MIN_INT); will cause # casting of x later. dtype = result_type(y, 1.) y = np.asanyarray(y, dtype) z = abs(x - y) if not issubdtype(z.dtype, number): z = z.astype(float_) # handle object arrays return z < 1.5 * 10.0**(-decimal) > assert_array_compare(compare, x, y, err_msg=err_msg, verbose=verbose, header=('Arrays are not almost equal to %d decimals' % decimal), precision=decimal) miniconda3/envs/myKwant/lib/python3.11/site-packages/numpy/testing/_private/utils.py:1099: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ args = (.compare at 0x13981d620>, array([[ 1.61723997, -1.50673361], [-1.50673361, 3.62336746]]), array([[1., 0.], [0., 1.]])) kwds = {'err_msg': '', 'header': 'Arrays are not almost equal to 7 decimals', 'precision': 7, 'verbose': True} @wraps(func) def inner(*args, **kwds): with self._recreate_cm(): > return func(*args, **kwds) miniconda3/envs/myKwant/lib/python3.11/contextlib.py:81: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ comparison = .compare at 0x13981d620> x = array([ 1.61723997, -1.50673361, -1.50673361, 3.62336746]) y = array([1., 0., 0., 1.]) err_msg = '\nMismatched elements: 4 / 4 (100%)\nMax absolute difference: 2.62336746\nMax relative difference: 2.62336746' verbose = True, header = 'Arrays are not almost equal to 7 decimals', precision = 7 equal_nan = True, equal_inf = True @np._no_nep50_warning() def assert_array_compare(comparison, x, y, err_msg='', verbose=True, header='', precision=6, equal_nan=True, equal_inf=True, *, strict=False): __tracebackhide__ = True # Hide traceback for py.test from numpy.core import array, array2string, isnan, inf, bool_, errstate, all, max, object_ x = np.asanyarray(x) y = np.asanyarray(y) # original array for output formatting ox, oy = x, y def isnumber(x): return x.dtype.char in '?bhilqpBHILQPefdgFDG' def istime(x): return x.dtype.char in "Mm" def func_assert_same_pos(x, y, func=isnan, hasval='nan'): """Handling nan/inf. Combine results of running func on x and y, checking that they are True at the same locations. """ __tracebackhide__ = True # Hide traceback for py.test x_id = func(x) y_id = func(y) # We include work-arounds here to handle three types of slightly # pathological ndarray subclasses: # (1) all() on `masked` array scalars can return masked arrays, so we # use != True # (2) __eq__ on some ndarray subclasses returns Python booleans # instead of element-wise comparisons, so we cast to bool_() and # use isinstance(..., bool) checks # (3) subclasses with bare-bones __array_function__ implementations may # not implement np.all(), so favor using the .all() method # We are not committed to supporting such subclasses, but it's nice to # support them if possible. if bool_(x_id == y_id).all() != True: msg = build_err_msg([x, y], err_msg + '\nx and y %s location mismatch:' % (hasval), verbose=verbose, header=header, names=('x', 'y'), precision=precision) raise AssertionError(msg) # If there is a scalar, then here we know the array has the same # flag as it everywhere, so we should return the scalar flag. if isinstance(x_id, bool) or x_id.ndim == 0: return bool_(x_id) elif isinstance(y_id, bool) or y_id.ndim == 0: return bool_(y_id) else: return y_id try: if strict: cond = x.shape == y.shape and x.dtype == y.dtype else: cond = (x.shape == () or y.shape == ()) or x.shape == y.shape if not cond: if x.shape != y.shape: reason = f'\n(shapes {x.shape}, {y.shape} mismatch)' else: reason = f'\n(dtypes {x.dtype}, {y.dtype} mismatch)' msg = build_err_msg([x, y], err_msg + reason, verbose=verbose, header=header, names=('x', 'y'), precision=precision) raise AssertionError(msg) flagged = bool_(False) if isnumber(x) and isnumber(y): if equal_nan: flagged = func_assert_same_pos(x, y, func=isnan, hasval='nan') if equal_inf: flagged |= func_assert_same_pos(x, y, func=lambda xy: xy == +inf, hasval='+inf') flagged |= func_assert_same_pos(x, y, func=lambda xy: xy == -inf, hasval='-inf') elif istime(x) and istime(y): # If one is datetime64 and the other timedelta64 there is no point if equal_nan and x.dtype.type == y.dtype.type: flagged = func_assert_same_pos(x, y, func=isnat, hasval="NaT") if flagged.ndim > 0: x, y = x[~flagged], y[~flagged] # Only do the comparison if actual values are left if x.size == 0: return elif flagged: # no sense doing comparison if everything is flagged. return val = comparison(x, y) if isinstance(val, bool): cond = val reduced = array([val]) else: reduced = val.ravel() cond = reduced.all() # The below comparison is a hack to ensure that fully masked # results, for which val.ravel().all() returns np.ma.masked, # do not trigger a failure (np.ma.masked != True evaluates as # np.ma.masked, which is falsy). if cond != True: n_mismatch = reduced.size - reduced.sum(dtype=intp) n_elements = flagged.size if flagged.ndim != 0 else reduced.size percent_mismatch = 100 * n_mismatch / n_elements remarks = [ 'Mismatched elements: {} / {} ({:.3g}%)'.format( n_mismatch, n_elements, percent_mismatch)] with errstate(all='ignore'): # ignore errors for non-numeric types with contextlib.suppress(TypeError): error = abs(x - y) if np.issubdtype(x.dtype, np.unsignedinteger): error2 = abs(y - x) np.minimum(error, error2, out=error) max_abs_error = max(error) if getattr(error, 'dtype', object_) == object_: remarks.append('Max absolute difference: ' + str(max_abs_error)) else: remarks.append('Max absolute difference: ' + array2string(max_abs_error)) # note: this definition of relative error matches that one # used by assert_allclose (found in np.isclose) # Filter values where the divisor would be zero nonzero = bool_(y != 0) if all(~nonzero): max_rel_error = array(inf) else: max_rel_error = max(error[nonzero] / abs(y[nonzero])) if getattr(error, 'dtype', object_) == object_: remarks.append('Max relative difference: ' + str(max_rel_error)) else: remarks.append('Max relative difference: ' + array2string(max_rel_error)) err_msg += '\n' + '\n'.join(remarks) msg = build_err_msg([ox, oy], err_msg, verbose=verbose, header=header, names=('x', 'y'), precision=precision) > raise AssertionError(msg) E AssertionError: E Arrays are not almost equal to 7 decimals E E Mismatched elements: 4 / 4 (100%) E Max absolute difference: 2.62336746 E Max relative difference: 2.62336746 E x: array([[ 1.61724 , -1.5067336], E [-1.5067336, 3.6233675]]) E y: array([[1., 0.], E [0., 1.]]) miniconda3/envs/myKwant/lib/python3.11/site-packages/numpy/testing/_private/utils.py:862: AssertionError During handling of the above exception, another exception occurred: def test_one_lead(): for opts in opt_list: reset_options() options(**opts) > _test_sparse.test_one_lead(smatrix) miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/test_mumps.py:39: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/_test_sparse.py:106: in test_one_lead assert_almost_equal(np.dot(s.conjugate().transpose(), s), _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ args = (array([[ 1.61723997-1.27997928e-18j, -1.50673361-1.07088697e+00j], [-1.50673361+1.07088697e+00j, 3.62336746+4.41835134e-18j]]), array([[1., 0.], [0., 1.]])) kwds = {} @wraps(func) def inner(*args, **kwds): with self._recreate_cm(): > return func(*args, **kwds) E AssertionError: E Arrays are not almost equal to 7 decimals E ACTUAL: array([[ 1.61723997-1.27997928e-18j, -1.50673361-1.07088697e+00j], E [-1.50673361+1.07088697e+00j, 3.62336746+4.41835134e-18j]]) E DESIRED: array([[1., 0.], E [0., 1.]]) miniconda3/envs/myKwant/lib/python3.11/contextlib.py:81: AssertionError __________________________________ test_two_equal_leads __________________________________ actual = array([[10.1159327 +8.14938380e-17j, 2.72402527-7.65569505e-01j, 1.82911428-1.51585055e+00j, 0.78535866-2.1...02881-2.66543230e-01j, -0.59466299-1.64211952e+00j, -2.85965839-2.39669481e+00j, 3.3791006 -6.38955953e-18j]]) desired = array([[1., 0., 0., 0., 0., 0.], [0., 1., 0., 0., 0., 0.], [0., 0., 1., 0., 0., 0.], [0., 0., 0., 1., 0., 0.], [0., 0., 0., 0., 1., 0.], [0., 0., 0., 0., 0., 1.]]) decimal = 7, err_msg = '', verbose = True @np._no_nep50_warning() def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=True): """ Raises an AssertionError if two items are not equal up to desired precision. .. note:: It is recommended to use one of `assert_allclose`, `assert_array_almost_equal_nulp` or `assert_array_max_ulp` instead of this function for more consistent floating point comparisons. The test verifies that the elements of `actual` and `desired` satisfy. ``abs(desired-actual) < float64(1.5 * 10**(-decimal))`` That is a looser test than originally documented, but agrees with what the actual implementation in `assert_array_almost_equal` did up to rounding vagaries. An exception is raised at conflicting values. For ndarrays this delegates to assert_array_almost_equal Parameters ---------- actual : array_like The object to check. desired : array_like The expected object. decimal : int, optional Desired precision, default is 7. err_msg : str, optional The error message to be printed in case of failure. verbose : bool, optional If True, the conflicting values are appended to the error message. Raises ------ AssertionError If actual and desired are not equal up to specified precision. See Also -------- assert_allclose: Compare two array_like objects for equality with desired relative and/or absolute precision. assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal Examples -------- >>> from numpy.testing import assert_almost_equal >>> assert_almost_equal(2.3333333333333, 2.33333334) >>> assert_almost_equal(2.3333333333333, 2.33333334, decimal=10) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 10 decimals ACTUAL: 2.3333333333333 DESIRED: 2.33333334 >>> assert_almost_equal(np.array([1.0,2.3333333333333]), ... np.array([1.0,2.33333334]), decimal=9) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 9 decimals Mismatched elements: 1 / 2 (50%) Max absolute difference: 6.66669964e-09 Max relative difference: 2.85715698e-09 x: array([1. , 2.333333333]) y: array([1. , 2.33333334]) """ __tracebackhide__ = True # Hide traceback for py.test from numpy.core import ndarray from numpy.lib import iscomplexobj, real, imag # Handle complex numbers: separate into real/imag to handle # nan/inf/negative zero correctly # XXX: catch ValueError for subclasses of ndarray where iscomplex fail try: usecomplex = iscomplexobj(actual) or iscomplexobj(desired) except ValueError: usecomplex = False def _build_err_msg(): header = ('Arrays are not almost equal to %d decimals' % decimal) return build_err_msg([actual, desired], err_msg, verbose=verbose, header=header) if usecomplex: if iscomplexobj(actual): actualr = real(actual) actuali = imag(actual) else: actualr = actual actuali = 0 if iscomplexobj(desired): desiredr = real(desired) desiredi = imag(desired) else: desiredr = desired desiredi = 0 try: > assert_almost_equal(actualr, desiredr, decimal=decimal) miniconda3/envs/myKwant/lib/python3.11/site-packages/numpy/testing/_private/utils.py:581: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ args = (array([[10.1159327 , 2.72402527, 1.82911428, 0.78535866, -7.69623179, 4.13390641], [ 2.72402527, ..., 1., 0., 0., 0.], [0., 0., 0., 1., 0., 0.], [0., 0., 0., 0., 1., 0.], [0., 0., 0., 0., 0., 1.]])) kwds = {'decimal': 7} @wraps(func) def inner(*args, **kwds): with self._recreate_cm(): > return func(*args, **kwds) miniconda3/envs/myKwant/lib/python3.11/contextlib.py:81: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ actual = array([[10.1159327 , 2.72402527, 1.82911428, 0.78535866, -7.69623179, 4.13390641], [ 2.72402527, 2..., -2.85965839], [ 4.13390641, 0.43655716, 1.29902881, -0.59466299, -2.85965839, 3.3791006 ]]) desired = array([[1., 0., 0., 0., 0., 0.], [0., 1., 0., 0., 0., 0.], [0., 0., 1., 0., 0., 0.], [0., 0., 0., 1., 0., 0.], [0., 0., 0., 0., 1., 0.], [0., 0., 0., 0., 0., 1.]]) decimal = 7, err_msg = '', verbose = True @np._no_nep50_warning() def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=True): """ Raises an AssertionError if two items are not equal up to desired precision. .. note:: It is recommended to use one of `assert_allclose`, `assert_array_almost_equal_nulp` or `assert_array_max_ulp` instead of this function for more consistent floating point comparisons. The test verifies that the elements of `actual` and `desired` satisfy. ``abs(desired-actual) < float64(1.5 * 10**(-decimal))`` That is a looser test than originally documented, but agrees with what the actual implementation in `assert_array_almost_equal` did up to rounding vagaries. An exception is raised at conflicting values. For ndarrays this delegates to assert_array_almost_equal Parameters ---------- actual : array_like The object to check. desired : array_like The expected object. decimal : int, optional Desired precision, default is 7. err_msg : str, optional The error message to be printed in case of failure. verbose : bool, optional If True, the conflicting values are appended to the error message. Raises ------ AssertionError If actual and desired are not equal up to specified precision. See Also -------- assert_allclose: Compare two array_like objects for equality with desired relative and/or absolute precision. assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal Examples -------- >>> from numpy.testing import assert_almost_equal >>> assert_almost_equal(2.3333333333333, 2.33333334) >>> assert_almost_equal(2.3333333333333, 2.33333334, decimal=10) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 10 decimals ACTUAL: 2.3333333333333 DESIRED: 2.33333334 >>> assert_almost_equal(np.array([1.0,2.3333333333333]), ... np.array([1.0,2.33333334]), decimal=9) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 9 decimals Mismatched elements: 1 / 2 (50%) Max absolute difference: 6.66669964e-09 Max relative difference: 2.85715698e-09 x: array([1. , 2.333333333]) y: array([1. , 2.33333334]) """ __tracebackhide__ = True # Hide traceback for py.test from numpy.core import ndarray from numpy.lib import iscomplexobj, real, imag # Handle complex numbers: separate into real/imag to handle # nan/inf/negative zero correctly # XXX: catch ValueError for subclasses of ndarray where iscomplex fail try: usecomplex = iscomplexobj(actual) or iscomplexobj(desired) except ValueError: usecomplex = False def _build_err_msg(): header = ('Arrays are not almost equal to %d decimals' % decimal) return build_err_msg([actual, desired], err_msg, verbose=verbose, header=header) if usecomplex: if iscomplexobj(actual): actualr = real(actual) actuali = imag(actual) else: actualr = actual actuali = 0 if iscomplexobj(desired): desiredr = real(desired) desiredi = imag(desired) else: desiredr = desired desiredi = 0 try: assert_almost_equal(actualr, desiredr, decimal=decimal) assert_almost_equal(actuali, desiredi, decimal=decimal) except AssertionError: raise AssertionError(_build_err_msg()) if isinstance(actual, (ndarray, tuple, list)) \ or isinstance(desired, (ndarray, tuple, list)): > return assert_array_almost_equal(actual, desired, decimal, err_msg) miniconda3/envs/myKwant/lib/python3.11/site-packages/numpy/testing/_private/utils.py:588: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ args = (array([[10.1159327 , 2.72402527, 1.82911428, 0.78535866, -7.69623179, 4.13390641], [ 2.72402527, ...., 0., 0.], [0., 0., 0., 1., 0., 0.], [0., 0., 0., 0., 1., 0.], [0., 0., 0., 0., 0., 1.]]), 7, '') kwds = {} @wraps(func) def inner(*args, **kwds): with self._recreate_cm(): > return func(*args, **kwds) miniconda3/envs/myKwant/lib/python3.11/contextlib.py:81: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ x = array([[10.1159327 , 2.72402527, 1.82911428, 0.78535866, -7.69623179, 4.13390641], [ 2.72402527, 2..., -2.85965839], [ 4.13390641, 0.43655716, 1.29902881, -0.59466299, -2.85965839, 3.3791006 ]]) y = array([[1., 0., 0., 0., 0., 0.], [0., 1., 0., 0., 0., 0.], [0., 0., 1., 0., 0., 0.], [0., 0., 0., 1., 0., 0.], [0., 0., 0., 0., 1., 0.], [0., 0., 0., 0., 0., 1.]]) decimal = 7, err_msg = '', verbose = True @np._no_nep50_warning() def assert_array_almost_equal(x, y, decimal=6, err_msg='', verbose=True): """ Raises an AssertionError if two objects are not equal up to desired precision. .. note:: It is recommended to use one of `assert_allclose`, `assert_array_almost_equal_nulp` or `assert_array_max_ulp` instead of this function for more consistent floating point comparisons. The test verifies identical shapes and that the elements of ``actual`` and ``desired`` satisfy. ``abs(desired-actual) < 1.5 * 10**(-decimal)`` That is a looser test than originally documented, but agrees with what the actual implementation did up to rounding vagaries. An exception is raised at shape mismatch or conflicting values. In contrast to the standard usage in numpy, NaNs are compared like numbers, no assertion is raised if both objects have NaNs in the same positions. Parameters ---------- x : array_like The actual object to check. y : array_like The desired, expected object. decimal : int, optional Desired precision, default is 6. err_msg : str, optional The error message to be printed in case of failure. verbose : bool, optional If True, the conflicting values are appended to the error message. Raises ------ AssertionError If actual and desired are not equal up to specified precision. See Also -------- assert_allclose: Compare two array_like objects for equality with desired relative and/or absolute precision. assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal Examples -------- the first assert does not raise an exception >>> np.testing.assert_array_almost_equal([1.0,2.333,np.nan], ... [1.0,2.333,np.nan]) >>> np.testing.assert_array_almost_equal([1.0,2.33333,np.nan], ... [1.0,2.33339,np.nan], decimal=5) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 5 decimals Mismatched elements: 1 / 3 (33.3%) Max absolute difference: 6.e-05 Max relative difference: 2.57136612e-05 x: array([1. , 2.33333, nan]) y: array([1. , 2.33339, nan]) >>> np.testing.assert_array_almost_equal([1.0,2.33333,np.nan], ... [1.0,2.33333, 5], decimal=5) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 5 decimals x and y nan location mismatch: x: array([1. , 2.33333, nan]) y: array([1. , 2.33333, 5. ]) """ __tracebackhide__ = True # Hide traceback for py.test from numpy.core import number, float_, result_type, array from numpy.core.numerictypes import issubdtype from numpy.core.fromnumeric import any as npany def compare(x, y): try: if npany(gisinf(x)) or npany( gisinf(y)): xinfid = gisinf(x) yinfid = gisinf(y) if not (xinfid == yinfid).all(): return False # if one item, x and y is +- inf if x.size == y.size == 1: return x == y x = x[~xinfid] y = y[~yinfid] except (TypeError, NotImplementedError): pass # make sure y is an inexact type to avoid abs(MIN_INT); will cause # casting of x later. dtype = result_type(y, 1.) y = np.asanyarray(y, dtype) z = abs(x - y) if not issubdtype(z.dtype, number): z = z.astype(float_) # handle object arrays return z < 1.5 * 10.0**(-decimal) > assert_array_compare(compare, x, y, err_msg=err_msg, verbose=verbose, header=('Arrays are not almost equal to %d decimals' % decimal), precision=decimal) miniconda3/envs/myKwant/lib/python3.11/site-packages/numpy/testing/_private/utils.py:1099: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ args = (.compare at 0x1398589a0>, array([[10.1159327 , 2.72402527, 1.82911428, ..., 1., 0., 0., 0.], [0., 0., 0., 1., 0., 0.], [0., 0., 0., 0., 1., 0.], [0., 0., 0., 0., 0., 1.]])) kwds = {'err_msg': '', 'header': 'Arrays are not almost equal to 7 decimals', 'precision': 7, 'verbose': True} @wraps(func) def inner(*args, **kwds): with self._recreate_cm(): > return func(*args, **kwds) miniconda3/envs/myKwant/lib/python3.11/contextlib.py:81: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ comparison = .compare at 0x1398589a0> x = array([10.1159327 , 2.72402527, 1.82911428, 0.78535866, -7.69623179, 4.13390641, 2.72402527, 2.12381414, ... 8.136419 , -2.85965839, 4.13390641, 0.43655716, 1.29902881, -0.59466299, -2.85965839, 3.3791006 ]) y = array([1., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 1.]) err_msg = '\nMismatched elements: 36 / 36 (100%)\nMax absolute difference: 9.1159327\nMax relative difference: 9.1159327' verbose = True, header = 'Arrays are not almost equal to 7 decimals', precision = 7 equal_nan = True, equal_inf = True @np._no_nep50_warning() def assert_array_compare(comparison, x, y, err_msg='', verbose=True, header='', precision=6, equal_nan=True, equal_inf=True, *, strict=False): __tracebackhide__ = True # Hide traceback for py.test from numpy.core import array, array2string, isnan, inf, bool_, errstate, all, max, object_ x = np.asanyarray(x) y = np.asanyarray(y) # original array for output formatting ox, oy = x, y def isnumber(x): return x.dtype.char in '?bhilqpBHILQPefdgFDG' def istime(x): return x.dtype.char in "Mm" def func_assert_same_pos(x, y, func=isnan, hasval='nan'): """Handling nan/inf. Combine results of running func on x and y, checking that they are True at the same locations. """ __tracebackhide__ = True # Hide traceback for py.test x_id = func(x) y_id = func(y) # We include work-arounds here to handle three types of slightly # pathological ndarray subclasses: # (1) all() on `masked` array scalars can return masked arrays, so we # use != True # (2) __eq__ on some ndarray subclasses returns Python booleans # instead of element-wise comparisons, so we cast to bool_() and # use isinstance(..., bool) checks # (3) subclasses with bare-bones __array_function__ implementations may # not implement np.all(), so favor using the .all() method # We are not committed to supporting such subclasses, but it's nice to # support them if possible. if bool_(x_id == y_id).all() != True: msg = build_err_msg([x, y], err_msg + '\nx and y %s location mismatch:' % (hasval), verbose=verbose, header=header, names=('x', 'y'), precision=precision) raise AssertionError(msg) # If there is a scalar, then here we know the array has the same # flag as it everywhere, so we should return the scalar flag. if isinstance(x_id, bool) or x_id.ndim == 0: return bool_(x_id) elif isinstance(y_id, bool) or y_id.ndim == 0: return bool_(y_id) else: return y_id try: if strict: cond = x.shape == y.shape and x.dtype == y.dtype else: cond = (x.shape == () or y.shape == ()) or x.shape == y.shape if not cond: if x.shape != y.shape: reason = f'\n(shapes {x.shape}, {y.shape} mismatch)' else: reason = f'\n(dtypes {x.dtype}, {y.dtype} mismatch)' msg = build_err_msg([x, y], err_msg + reason, verbose=verbose, header=header, names=('x', 'y'), precision=precision) raise AssertionError(msg) flagged = bool_(False) if isnumber(x) and isnumber(y): if equal_nan: flagged = func_assert_same_pos(x, y, func=isnan, hasval='nan') if equal_inf: flagged |= func_assert_same_pos(x, y, func=lambda xy: xy == +inf, hasval='+inf') flagged |= func_assert_same_pos(x, y, func=lambda xy: xy == -inf, hasval='-inf') elif istime(x) and istime(y): # If one is datetime64 and the other timedelta64 there is no point if equal_nan and x.dtype.type == y.dtype.type: flagged = func_assert_same_pos(x, y, func=isnat, hasval="NaT") if flagged.ndim > 0: x, y = x[~flagged], y[~flagged] # Only do the comparison if actual values are left if x.size == 0: return elif flagged: # no sense doing comparison if everything is flagged. return val = comparison(x, y) if isinstance(val, bool): cond = val reduced = array([val]) else: reduced = val.ravel() cond = reduced.all() # The below comparison is a hack to ensure that fully masked # results, for which val.ravel().all() returns np.ma.masked, # do not trigger a failure (np.ma.masked != True evaluates as # np.ma.masked, which is falsy). if cond != True: n_mismatch = reduced.size - reduced.sum(dtype=intp) n_elements = flagged.size if flagged.ndim != 0 else reduced.size percent_mismatch = 100 * n_mismatch / n_elements remarks = [ 'Mismatched elements: {} / {} ({:.3g}%)'.format( n_mismatch, n_elements, percent_mismatch)] with errstate(all='ignore'): # ignore errors for non-numeric types with contextlib.suppress(TypeError): error = abs(x - y) if np.issubdtype(x.dtype, np.unsignedinteger): error2 = abs(y - x) np.minimum(error, error2, out=error) max_abs_error = max(error) if getattr(error, 'dtype', object_) == object_: remarks.append('Max absolute difference: ' + str(max_abs_error)) else: remarks.append('Max absolute difference: ' + array2string(max_abs_error)) # note: this definition of relative error matches that one # used by assert_allclose (found in np.isclose) # Filter values where the divisor would be zero nonzero = bool_(y != 0) if all(~nonzero): max_rel_error = array(inf) else: max_rel_error = max(error[nonzero] / abs(y[nonzero])) if getattr(error, 'dtype', object_) == object_: remarks.append('Max relative difference: ' + str(max_rel_error)) else: remarks.append('Max relative difference: ' + array2string(max_rel_error)) err_msg += '\n' + '\n'.join(remarks) msg = build_err_msg([ox, oy], err_msg, verbose=verbose, header=header, names=('x', 'y'), precision=precision) > raise AssertionError(msg) E AssertionError: E Arrays are not almost equal to 7 decimals E E Mismatched elements: 36 / 36 (100%) E Max absolute difference: 9.1159327 E Max relative difference: 9.1159327 E x: array([[10.1159327, 2.7240253, 1.8291143, 0.7853587, -7.6962318, E 4.1339064], E [ 2.7240253, 2.1238141, 0.5551859, 1.7557896, -2.1628183,... E y: array([[1., 0., 0., 0., 0., 0.], E [0., 1., 0., 0., 0., 0.], E [0., 0., 1., 0., 0., 0.],... miniconda3/envs/myKwant/lib/python3.11/site-packages/numpy/testing/_private/utils.py:862: AssertionError During handling of the above exception, another exception occurred: def test_two_equal_leads(): for opts in opt_list: reset_options() options(**opts) > _test_sparse.test_two_equal_leads(smatrix) miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/test_mumps.py:53: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/_test_sparse.py:182: in test_two_equal_leads check_fsyst(syst) miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/_test_sparse.py:159: in check_fsyst assert_almost_equal(np.dot(s.conjugate().transpose(), s), _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ args = (array([[10.1159327 +8.14938380e-17j, 2.72402527-7.65569505e-01j, 1.82911428-1.51585055e+00j, 0.78535866-2...., 1., 0., 0., 0.], [0., 0., 0., 1., 0., 0.], [0., 0., 0., 0., 1., 0.], [0., 0., 0., 0., 0., 1.]])) kwds = {} @wraps(func) def inner(*args, **kwds): with self._recreate_cm(): > return func(*args, **kwds) E AssertionError: E Arrays are not almost equal to 7 decimals E ACTUAL: array([[10.1159327 +8.14938380e-17j, 2.72402527-7.65569505e-01j, E 1.82911428-1.51585055e+00j, 0.78535866-2.18958927e+00j, E -7.69623179-2.69263438e+00j, 4.13390641-2.01803562e+00j],... E DESIRED: array([[1., 0., 0., 0., 0., 0.], E [0., 1., 0., 0., 0., 0.], E [0., 0., 1., 0., 0., 0.],... miniconda3/envs/myKwant/lib/python3.11/contextlib.py:81: AssertionError ___________________________________ test_graph_system ____________________________________ actual = array([[ 1.74525101-2.29050355e-17j, 1.06360436-3.28809495e+00j, 0.02293837+2.04429560e+00j, 0.67436678+9.2...36678-9.27177276e-01j, -2.58172198-6.61543911e-01j, 1.70995375-2.40268501e-01j, 1.37157558-4.16397188e-18j]]) desired = array([[1., 0., 0., 0.], [0., 1., 0., 0.], [0., 0., 1., 0.], [0., 0., 0., 1.]]) decimal = 7, err_msg = '', verbose = True @np._no_nep50_warning() def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=True): """ Raises an AssertionError if two items are not equal up to desired precision. .. note:: It is recommended to use one of `assert_allclose`, `assert_array_almost_equal_nulp` or `assert_array_max_ulp` instead of this function for more consistent floating point comparisons. The test verifies that the elements of `actual` and `desired` satisfy. ``abs(desired-actual) < float64(1.5 * 10**(-decimal))`` That is a looser test than originally documented, but agrees with what the actual implementation in `assert_array_almost_equal` did up to rounding vagaries. An exception is raised at conflicting values. For ndarrays this delegates to assert_array_almost_equal Parameters ---------- actual : array_like The object to check. desired : array_like The expected object. decimal : int, optional Desired precision, default is 7. err_msg : str, optional The error message to be printed in case of failure. verbose : bool, optional If True, the conflicting values are appended to the error message. Raises ------ AssertionError If actual and desired are not equal up to specified precision. See Also -------- assert_allclose: Compare two array_like objects for equality with desired relative and/or absolute precision. assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal Examples -------- >>> from numpy.testing import assert_almost_equal >>> assert_almost_equal(2.3333333333333, 2.33333334) >>> assert_almost_equal(2.3333333333333, 2.33333334, decimal=10) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 10 decimals ACTUAL: 2.3333333333333 DESIRED: 2.33333334 >>> assert_almost_equal(np.array([1.0,2.3333333333333]), ... np.array([1.0,2.33333334]), decimal=9) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 9 decimals Mismatched elements: 1 / 2 (50%) Max absolute difference: 6.66669964e-09 Max relative difference: 2.85715698e-09 x: array([1. , 2.333333333]) y: array([1. , 2.33333334]) """ __tracebackhide__ = True # Hide traceback for py.test from numpy.core import ndarray from numpy.lib import iscomplexobj, real, imag # Handle complex numbers: separate into real/imag to handle # nan/inf/negative zero correctly # XXX: catch ValueError for subclasses of ndarray where iscomplex fail try: usecomplex = iscomplexobj(actual) or iscomplexobj(desired) except ValueError: usecomplex = False def _build_err_msg(): header = ('Arrays are not almost equal to %d decimals' % decimal) return build_err_msg([actual, desired], err_msg, verbose=verbose, header=header) if usecomplex: if iscomplexobj(actual): actualr = real(actual) actuali = imag(actual) else: actualr = actual actuali = 0 if iscomplexobj(desired): desiredr = real(desired) desiredi = imag(desired) else: desiredr = desired desiredi = 0 try: > assert_almost_equal(actualr, desiredr, decimal=decimal) miniconda3/envs/myKwant/lib/python3.11/site-packages/numpy/testing/_private/utils.py:581: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ args = (array([[ 1.74525101, 1.06360436, 0.02293837, 0.67436678], [ 1.06360436, 12.76698827, -7.70287447, -2.581721..., 1.37157558]]), array([[1., 0., 0., 0.], [0., 1., 0., 0.], [0., 0., 1., 0.], [0., 0., 0., 1.]])) kwds = {'decimal': 7} @wraps(func) def inner(*args, **kwds): with self._recreate_cm(): > return func(*args, **kwds) miniconda3/envs/myKwant/lib/python3.11/contextlib.py:81: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ actual = array([[ 1.74525101, 1.06360436, 0.02293837, 0.67436678], [ 1.06360436, 12.76698827, -7.70287447, -2.5817219... [ 0.02293837, -7.70287447, 5.60015815, 1.70995375], [ 0.67436678, -2.58172198, 1.70995375, 1.37157558]]) desired = array([[1., 0., 0., 0.], [0., 1., 0., 0.], [0., 0., 1., 0.], [0., 0., 0., 1.]]) decimal = 7, err_msg = '', verbose = True @np._no_nep50_warning() def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=True): """ Raises an AssertionError if two items are not equal up to desired precision. .. note:: It is recommended to use one of `assert_allclose`, `assert_array_almost_equal_nulp` or `assert_array_max_ulp` instead of this function for more consistent floating point comparisons. The test verifies that the elements of `actual` and `desired` satisfy. ``abs(desired-actual) < float64(1.5 * 10**(-decimal))`` That is a looser test than originally documented, but agrees with what the actual implementation in `assert_array_almost_equal` did up to rounding vagaries. An exception is raised at conflicting values. For ndarrays this delegates to assert_array_almost_equal Parameters ---------- actual : array_like The object to check. desired : array_like The expected object. decimal : int, optional Desired precision, default is 7. err_msg : str, optional The error message to be printed in case of failure. verbose : bool, optional If True, the conflicting values are appended to the error message. Raises ------ AssertionError If actual and desired are not equal up to specified precision. See Also -------- assert_allclose: Compare two array_like objects for equality with desired relative and/or absolute precision. assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal Examples -------- >>> from numpy.testing import assert_almost_equal >>> assert_almost_equal(2.3333333333333, 2.33333334) >>> assert_almost_equal(2.3333333333333, 2.33333334, decimal=10) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 10 decimals ACTUAL: 2.3333333333333 DESIRED: 2.33333334 >>> assert_almost_equal(np.array([1.0,2.3333333333333]), ... np.array([1.0,2.33333334]), decimal=9) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 9 decimals Mismatched elements: 1 / 2 (50%) Max absolute difference: 6.66669964e-09 Max relative difference: 2.85715698e-09 x: array([1. , 2.333333333]) y: array([1. , 2.33333334]) """ __tracebackhide__ = True # Hide traceback for py.test from numpy.core import ndarray from numpy.lib import iscomplexobj, real, imag # Handle complex numbers: separate into real/imag to handle # nan/inf/negative zero correctly # XXX: catch ValueError for subclasses of ndarray where iscomplex fail try: usecomplex = iscomplexobj(actual) or iscomplexobj(desired) except ValueError: usecomplex = False def _build_err_msg(): header = ('Arrays are not almost equal to %d decimals' % decimal) return build_err_msg([actual, desired], err_msg, verbose=verbose, header=header) if usecomplex: if iscomplexobj(actual): actualr = real(actual) actuali = imag(actual) else: actualr = actual actuali = 0 if iscomplexobj(desired): desiredr = real(desired) desiredi = imag(desired) else: desiredr = desired desiredi = 0 try: assert_almost_equal(actualr, desiredr, decimal=decimal) assert_almost_equal(actuali, desiredi, decimal=decimal) except AssertionError: raise AssertionError(_build_err_msg()) if isinstance(actual, (ndarray, tuple, list)) \ or isinstance(desired, (ndarray, tuple, list)): > return assert_array_almost_equal(actual, desired, decimal, err_msg) miniconda3/envs/myKwant/lib/python3.11/site-packages/numpy/testing/_private/utils.py:588: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ args = (array([[ 1.74525101, 1.06360436, 0.02293837, 0.67436678], [ 1.06360436, 12.76698827, -7.70287447, -2.581721...157558]]), array([[1., 0., 0., 0.], [0., 1., 0., 0.], [0., 0., 1., 0.], [0., 0., 0., 1.]]), 7, '') kwds = {} @wraps(func) def inner(*args, **kwds): with self._recreate_cm(): > return func(*args, **kwds) miniconda3/envs/myKwant/lib/python3.11/contextlib.py:81: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ x = array([[ 1.74525101, 1.06360436, 0.02293837, 0.67436678], [ 1.06360436, 12.76698827, -7.70287447, -2.5817219... [ 0.02293837, -7.70287447, 5.60015815, 1.70995375], [ 0.67436678, -2.58172198, 1.70995375, 1.37157558]]) y = array([[1., 0., 0., 0.], [0., 1., 0., 0.], [0., 0., 1., 0.], [0., 0., 0., 1.]]) decimal = 7, err_msg = '', verbose = True @np._no_nep50_warning() def assert_array_almost_equal(x, y, decimal=6, err_msg='', verbose=True): """ Raises an AssertionError if two objects are not equal up to desired precision. .. note:: It is recommended to use one of `assert_allclose`, `assert_array_almost_equal_nulp` or `assert_array_max_ulp` instead of this function for more consistent floating point comparisons. The test verifies identical shapes and that the elements of ``actual`` and ``desired`` satisfy. ``abs(desired-actual) < 1.5 * 10**(-decimal)`` That is a looser test than originally documented, but agrees with what the actual implementation did up to rounding vagaries. An exception is raised at shape mismatch or conflicting values. In contrast to the standard usage in numpy, NaNs are compared like numbers, no assertion is raised if both objects have NaNs in the same positions. Parameters ---------- x : array_like The actual object to check. y : array_like The desired, expected object. decimal : int, optional Desired precision, default is 6. err_msg : str, optional The error message to be printed in case of failure. verbose : bool, optional If True, the conflicting values are appended to the error message. Raises ------ AssertionError If actual and desired are not equal up to specified precision. See Also -------- assert_allclose: Compare two array_like objects for equality with desired relative and/or absolute precision. assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal Examples -------- the first assert does not raise an exception >>> np.testing.assert_array_almost_equal([1.0,2.333,np.nan], ... [1.0,2.333,np.nan]) >>> np.testing.assert_array_almost_equal([1.0,2.33333,np.nan], ... [1.0,2.33339,np.nan], decimal=5) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 5 decimals Mismatched elements: 1 / 3 (33.3%) Max absolute difference: 6.e-05 Max relative difference: 2.57136612e-05 x: array([1. , 2.33333, nan]) y: array([1. , 2.33339, nan]) >>> np.testing.assert_array_almost_equal([1.0,2.33333,np.nan], ... [1.0,2.33333, 5], decimal=5) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 5 decimals x and y nan location mismatch: x: array([1. , 2.33333, nan]) y: array([1. , 2.33333, 5. ]) """ __tracebackhide__ = True # Hide traceback for py.test from numpy.core import number, float_, result_type, array from numpy.core.numerictypes import issubdtype from numpy.core.fromnumeric import any as npany def compare(x, y): try: if npany(gisinf(x)) or npany( gisinf(y)): xinfid = gisinf(x) yinfid = gisinf(y) if not (xinfid == yinfid).all(): return False # if one item, x and y is +- inf if x.size == y.size == 1: return x == y x = x[~xinfid] y = y[~yinfid] except (TypeError, NotImplementedError): pass # make sure y is an inexact type to avoid abs(MIN_INT); will cause # casting of x later. dtype = result_type(y, 1.) y = np.asanyarray(y, dtype) z = abs(x - y) if not issubdtype(z.dtype, number): z = z.astype(float_) # handle object arrays return z < 1.5 * 10.0**(-decimal) > assert_array_compare(compare, x, y, err_msg=err_msg, verbose=verbose, header=('Arrays are not almost equal to %d decimals' % decimal), precision=decimal) miniconda3/envs/myKwant/lib/python3.11/site-packages/numpy/testing/_private/utils.py:1099: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ args = (.compare at 0x139a391c0>, array([[ 1.74525101, 1.06360436, 0.02293837, ..., 1.37157558]]), array([[1., 0., 0., 0.], [0., 1., 0., 0.], [0., 0., 1., 0.], [0., 0., 0., 1.]])) kwds = {'err_msg': '', 'header': 'Arrays are not almost equal to 7 decimals', 'precision': 7, 'verbose': True} @wraps(func) def inner(*args, **kwds): with self._recreate_cm(): > return func(*args, **kwds) miniconda3/envs/myKwant/lib/python3.11/contextlib.py:81: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ comparison = .compare at 0x139a391c0> x = array([ 1.74525101, 1.06360436, 0.02293837, 0.67436678, 1.06360436, 12.76698827, -7.70287447, -2.58172198, 0.02293837, -7.70287447, 5.60015815, 1.70995375, 0.67436678, -2.58172198, 1.70995375, 1.37157558]) y = array([1., 0., 0., 0., 0., 1., 0., 0., 0., 0., 1., 0., 0., 0., 0., 1.]) err_msg = '\nMismatched elements: 16 / 16 (100%)\nMax absolute difference: 11.76698827\nMax relative difference: 11.76698827' verbose = True, header = 'Arrays are not almost equal to 7 decimals', precision = 7 equal_nan = True, equal_inf = True @np._no_nep50_warning() def assert_array_compare(comparison, x, y, err_msg='', verbose=True, header='', precision=6, equal_nan=True, equal_inf=True, *, strict=False): __tracebackhide__ = True # Hide traceback for py.test from numpy.core import array, array2string, isnan, inf, bool_, errstate, all, max, object_ x = np.asanyarray(x) y = np.asanyarray(y) # original array for output formatting ox, oy = x, y def isnumber(x): return x.dtype.char in '?bhilqpBHILQPefdgFDG' def istime(x): return x.dtype.char in "Mm" def func_assert_same_pos(x, y, func=isnan, hasval='nan'): """Handling nan/inf. Combine results of running func on x and y, checking that they are True at the same locations. """ __tracebackhide__ = True # Hide traceback for py.test x_id = func(x) y_id = func(y) # We include work-arounds here to handle three types of slightly # pathological ndarray subclasses: # (1) all() on `masked` array scalars can return masked arrays, so we # use != True # (2) __eq__ on some ndarray subclasses returns Python booleans # instead of element-wise comparisons, so we cast to bool_() and # use isinstance(..., bool) checks # (3) subclasses with bare-bones __array_function__ implementations may # not implement np.all(), so favor using the .all() method # We are not committed to supporting such subclasses, but it's nice to # support them if possible. if bool_(x_id == y_id).all() != True: msg = build_err_msg([x, y], err_msg + '\nx and y %s location mismatch:' % (hasval), verbose=verbose, header=header, names=('x', 'y'), precision=precision) raise AssertionError(msg) # If there is a scalar, then here we know the array has the same # flag as it everywhere, so we should return the scalar flag. if isinstance(x_id, bool) or x_id.ndim == 0: return bool_(x_id) elif isinstance(y_id, bool) or y_id.ndim == 0: return bool_(y_id) else: return y_id try: if strict: cond = x.shape == y.shape and x.dtype == y.dtype else: cond = (x.shape == () or y.shape == ()) or x.shape == y.shape if not cond: if x.shape != y.shape: reason = f'\n(shapes {x.shape}, {y.shape} mismatch)' else: reason = f'\n(dtypes {x.dtype}, {y.dtype} mismatch)' msg = build_err_msg([x, y], err_msg + reason, verbose=verbose, header=header, names=('x', 'y'), precision=precision) raise AssertionError(msg) flagged = bool_(False) if isnumber(x) and isnumber(y): if equal_nan: flagged = func_assert_same_pos(x, y, func=isnan, hasval='nan') if equal_inf: flagged |= func_assert_same_pos(x, y, func=lambda xy: xy == +inf, hasval='+inf') flagged |= func_assert_same_pos(x, y, func=lambda xy: xy == -inf, hasval='-inf') elif istime(x) and istime(y): # If one is datetime64 and the other timedelta64 there is no point if equal_nan and x.dtype.type == y.dtype.type: flagged = func_assert_same_pos(x, y, func=isnat, hasval="NaT") if flagged.ndim > 0: x, y = x[~flagged], y[~flagged] # Only do the comparison if actual values are left if x.size == 0: return elif flagged: # no sense doing comparison if everything is flagged. return val = comparison(x, y) if isinstance(val, bool): cond = val reduced = array([val]) else: reduced = val.ravel() cond = reduced.all() # The below comparison is a hack to ensure that fully masked # results, for which val.ravel().all() returns np.ma.masked, # do not trigger a failure (np.ma.masked != True evaluates as # np.ma.masked, which is falsy). if cond != True: n_mismatch = reduced.size - reduced.sum(dtype=intp) n_elements = flagged.size if flagged.ndim != 0 else reduced.size percent_mismatch = 100 * n_mismatch / n_elements remarks = [ 'Mismatched elements: {} / {} ({:.3g}%)'.format( n_mismatch, n_elements, percent_mismatch)] with errstate(all='ignore'): # ignore errors for non-numeric types with contextlib.suppress(TypeError): error = abs(x - y) if np.issubdtype(x.dtype, np.unsignedinteger): error2 = abs(y - x) np.minimum(error, error2, out=error) max_abs_error = max(error) if getattr(error, 'dtype', object_) == object_: remarks.append('Max absolute difference: ' + str(max_abs_error)) else: remarks.append('Max absolute difference: ' + array2string(max_abs_error)) # note: this definition of relative error matches that one # used by assert_allclose (found in np.isclose) # Filter values where the divisor would be zero nonzero = bool_(y != 0) if all(~nonzero): max_rel_error = array(inf) else: max_rel_error = max(error[nonzero] / abs(y[nonzero])) if getattr(error, 'dtype', object_) == object_: remarks.append('Max relative difference: ' + str(max_rel_error)) else: remarks.append('Max relative difference: ' + array2string(max_rel_error)) err_msg += '\n' + '\n'.join(remarks) msg = build_err_msg([ox, oy], err_msg, verbose=verbose, header=header, names=('x', 'y'), precision=precision) > raise AssertionError(msg) E AssertionError: E Arrays are not almost equal to 7 decimals E E Mismatched elements: 16 / 16 (100%) E Max absolute difference: 11.76698827 E Max relative difference: 11.76698827 E x: array([[ 1.745251 , 1.0636044, 0.0229384, 0.6743668], E [ 1.0636044, 12.7669883, -7.7028745, -2.581722 ], E [ 0.0229384, -7.7028745, 5.6001581, 1.7099537], E [ 0.6743668, -2.581722 , 1.7099537, 1.3715756]]) E y: array([[1., 0., 0., 0.], E [0., 1., 0., 0.], E [0., 0., 1., 0.], E [0., 0., 0., 1.]]) miniconda3/envs/myKwant/lib/python3.11/site-packages/numpy/testing/_private/utils.py:862: AssertionError During handling of the above exception, another exception occurred: def test_graph_system(): for opts in opt_list: reset_options() options(**opts) > _test_sparse.test_graph_system(smatrix) miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/test_mumps.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/_test_sparse.py:219: in test_graph_system assert_almost_equal(np.dot(s.conjugate().transpose(), s), _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ args = (array([[ 1.74525101-2.29050355e-17j, 1.06360436-3.28809495e+00j, 0.02293837+2.04429560e+00j, 0.67436678+9....16397188e-18j]]), array([[1., 0., 0., 0.], [0., 1., 0., 0.], [0., 0., 1., 0.], [0., 0., 0., 1.]])) kwds = {} @wraps(func) def inner(*args, **kwds): with self._recreate_cm(): > return func(*args, **kwds) E AssertionError: E Arrays are not almost equal to 7 decimals E ACTUAL: array([[ 1.74525101-2.29050355e-17j, 1.06360436-3.28809495e+00j, E 0.02293837+2.04429560e+00j, 0.67436678+9.27177276e-01j], E [ 1.06360436+3.28809495e+00j, 12.76698827+3.86780230e-17j,... E DESIRED: array([[1., 0., 0., 0.], E [0., 1., 0., 0.], E [0., 0., 1., 0.], E [0., 0., 0., 1.]]) miniconda3/envs/myKwant/lib/python3.11/contextlib.py:81: AssertionError _______________________________ test_singular_graph_system _______________________________ actual = array([[17.35003728-2.10086905e-17j, 0.83272758+3.86226056e-01j, 12.77101887-1.63874544e+01j, -4.7021894 -6.6...1894 +6.61464843e-01j, -1.75998971-5.59067803e+00j, -7.66975788+1.18054206e+01j, 8.20972779+1.61345408e-17j]]) desired = array([[1., 0., 0., 0.], [0., 1., 0., 0.], [0., 0., 1., 0.], [0., 0., 0., 1.]]) decimal = 7, err_msg = '', verbose = True @np._no_nep50_warning() def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=True): """ Raises an AssertionError if two items are not equal up to desired precision. .. note:: It is recommended to use one of `assert_allclose`, `assert_array_almost_equal_nulp` or `assert_array_max_ulp` instead of this function for more consistent floating point comparisons. The test verifies that the elements of `actual` and `desired` satisfy. ``abs(desired-actual) < float64(1.5 * 10**(-decimal))`` That is a looser test than originally documented, but agrees with what the actual implementation in `assert_array_almost_equal` did up to rounding vagaries. An exception is raised at conflicting values. For ndarrays this delegates to assert_array_almost_equal Parameters ---------- actual : array_like The object to check. desired : array_like The expected object. decimal : int, optional Desired precision, default is 7. err_msg : str, optional The error message to be printed in case of failure. verbose : bool, optional If True, the conflicting values are appended to the error message. Raises ------ AssertionError If actual and desired are not equal up to specified precision. See Also -------- assert_allclose: Compare two array_like objects for equality with desired relative and/or absolute precision. assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal Examples -------- >>> from numpy.testing import assert_almost_equal >>> assert_almost_equal(2.3333333333333, 2.33333334) >>> assert_almost_equal(2.3333333333333, 2.33333334, decimal=10) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 10 decimals ACTUAL: 2.3333333333333 DESIRED: 2.33333334 >>> assert_almost_equal(np.array([1.0,2.3333333333333]), ... np.array([1.0,2.33333334]), decimal=9) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 9 decimals Mismatched elements: 1 / 2 (50%) Max absolute difference: 6.66669964e-09 Max relative difference: 2.85715698e-09 x: array([1. , 2.333333333]) y: array([1. , 2.33333334]) """ __tracebackhide__ = True # Hide traceback for py.test from numpy.core import ndarray from numpy.lib import iscomplexobj, real, imag # Handle complex numbers: separate into real/imag to handle # nan/inf/negative zero correctly # XXX: catch ValueError for subclasses of ndarray where iscomplex fail try: usecomplex = iscomplexobj(actual) or iscomplexobj(desired) except ValueError: usecomplex = False def _build_err_msg(): header = ('Arrays are not almost equal to %d decimals' % decimal) return build_err_msg([actual, desired], err_msg, verbose=verbose, header=header) if usecomplex: if iscomplexobj(actual): actualr = real(actual) actuali = imag(actual) else: actualr = actual actuali = 0 if iscomplexobj(desired): desiredr = real(desired) desiredi = imag(desired) else: desiredr = desired desiredi = 0 try: > assert_almost_equal(actualr, desiredr, decimal=decimal) miniconda3/envs/myKwant/lib/python3.11/site-packages/numpy/testing/_private/utils.py:581: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ args = (array([[17.35003728, 0.83272758, 12.77101887, -4.7021894 ], [ 0.83272758, 5.31817007, -3.89030484, -1.759989..., 8.20972779]]), array([[1., 0., 0., 0.], [0., 1., 0., 0.], [0., 0., 1., 0.], [0., 0., 0., 1.]])) kwds = {'decimal': 7} @wraps(func) def inner(*args, **kwds): with self._recreate_cm(): > return func(*args, **kwds) miniconda3/envs/myKwant/lib/python3.11/contextlib.py:81: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ actual = array([[17.35003728, 0.83272758, 12.77101887, -4.7021894 ], [ 0.83272758, 5.31817007, -3.89030484, -1.7599897... [12.77101887, -3.89030484, 35.55422496, -7.66975788], [-4.7021894 , -1.75998971, -7.66975788, 8.20972779]]) desired = array([[1., 0., 0., 0.], [0., 1., 0., 0.], [0., 0., 1., 0.], [0., 0., 0., 1.]]) decimal = 7, err_msg = '', verbose = True @np._no_nep50_warning() def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=True): """ Raises an AssertionError if two items are not equal up to desired precision. .. note:: It is recommended to use one of `assert_allclose`, `assert_array_almost_equal_nulp` or `assert_array_max_ulp` instead of this function for more consistent floating point comparisons. The test verifies that the elements of `actual` and `desired` satisfy. ``abs(desired-actual) < float64(1.5 * 10**(-decimal))`` That is a looser test than originally documented, but agrees with what the actual implementation in `assert_array_almost_equal` did up to rounding vagaries. An exception is raised at conflicting values. For ndarrays this delegates to assert_array_almost_equal Parameters ---------- actual : array_like The object to check. desired : array_like The expected object. decimal : int, optional Desired precision, default is 7. err_msg : str, optional The error message to be printed in case of failure. verbose : bool, optional If True, the conflicting values are appended to the error message. Raises ------ AssertionError If actual and desired are not equal up to specified precision. See Also -------- assert_allclose: Compare two array_like objects for equality with desired relative and/or absolute precision. assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal Examples -------- >>> from numpy.testing import assert_almost_equal >>> assert_almost_equal(2.3333333333333, 2.33333334) >>> assert_almost_equal(2.3333333333333, 2.33333334, decimal=10) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 10 decimals ACTUAL: 2.3333333333333 DESIRED: 2.33333334 >>> assert_almost_equal(np.array([1.0,2.3333333333333]), ... np.array([1.0,2.33333334]), decimal=9) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 9 decimals Mismatched elements: 1 / 2 (50%) Max absolute difference: 6.66669964e-09 Max relative difference: 2.85715698e-09 x: array([1. , 2.333333333]) y: array([1. , 2.33333334]) """ __tracebackhide__ = True # Hide traceback for py.test from numpy.core import ndarray from numpy.lib import iscomplexobj, real, imag # Handle complex numbers: separate into real/imag to handle # nan/inf/negative zero correctly # XXX: catch ValueError for subclasses of ndarray where iscomplex fail try: usecomplex = iscomplexobj(actual) or iscomplexobj(desired) except ValueError: usecomplex = False def _build_err_msg(): header = ('Arrays are not almost equal to %d decimals' % decimal) return build_err_msg([actual, desired], err_msg, verbose=verbose, header=header) if usecomplex: if iscomplexobj(actual): actualr = real(actual) actuali = imag(actual) else: actualr = actual actuali = 0 if iscomplexobj(desired): desiredr = real(desired) desiredi = imag(desired) else: desiredr = desired desiredi = 0 try: assert_almost_equal(actualr, desiredr, decimal=decimal) assert_almost_equal(actuali, desiredi, decimal=decimal) except AssertionError: raise AssertionError(_build_err_msg()) if isinstance(actual, (ndarray, tuple, list)) \ or isinstance(desired, (ndarray, tuple, list)): > return assert_array_almost_equal(actual, desired, decimal, err_msg) miniconda3/envs/myKwant/lib/python3.11/site-packages/numpy/testing/_private/utils.py:588: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ args = (array([[17.35003728, 0.83272758, 12.77101887, -4.7021894 ], [ 0.83272758, 5.31817007, -3.89030484, -1.759989...972779]]), array([[1., 0., 0., 0.], [0., 1., 0., 0.], [0., 0., 1., 0.], [0., 0., 0., 1.]]), 7, '') kwds = {} @wraps(func) def inner(*args, **kwds): with self._recreate_cm(): > return func(*args, **kwds) miniconda3/envs/myKwant/lib/python3.11/contextlib.py:81: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ x = array([[17.35003728, 0.83272758, 12.77101887, -4.7021894 ], [ 0.83272758, 5.31817007, -3.89030484, -1.7599897... [12.77101887, -3.89030484, 35.55422496, -7.66975788], [-4.7021894 , -1.75998971, -7.66975788, 8.20972779]]) y = array([[1., 0., 0., 0.], [0., 1., 0., 0.], [0., 0., 1., 0.], [0., 0., 0., 1.]]) decimal = 7, err_msg = '', verbose = True @np._no_nep50_warning() def assert_array_almost_equal(x, y, decimal=6, err_msg='', verbose=True): """ Raises an AssertionError if two objects are not equal up to desired precision. .. note:: It is recommended to use one of `assert_allclose`, `assert_array_almost_equal_nulp` or `assert_array_max_ulp` instead of this function for more consistent floating point comparisons. The test verifies identical shapes and that the elements of ``actual`` and ``desired`` satisfy. ``abs(desired-actual) < 1.5 * 10**(-decimal)`` That is a looser test than originally documented, but agrees with what the actual implementation did up to rounding vagaries. An exception is raised at shape mismatch or conflicting values. In contrast to the standard usage in numpy, NaNs are compared like numbers, no assertion is raised if both objects have NaNs in the same positions. Parameters ---------- x : array_like The actual object to check. y : array_like The desired, expected object. decimal : int, optional Desired precision, default is 6. err_msg : str, optional The error message to be printed in case of failure. verbose : bool, optional If True, the conflicting values are appended to the error message. Raises ------ AssertionError If actual and desired are not equal up to specified precision. See Also -------- assert_allclose: Compare two array_like objects for equality with desired relative and/or absolute precision. assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal Examples -------- the first assert does not raise an exception >>> np.testing.assert_array_almost_equal([1.0,2.333,np.nan], ... [1.0,2.333,np.nan]) >>> np.testing.assert_array_almost_equal([1.0,2.33333,np.nan], ... [1.0,2.33339,np.nan], decimal=5) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 5 decimals Mismatched elements: 1 / 3 (33.3%) Max absolute difference: 6.e-05 Max relative difference: 2.57136612e-05 x: array([1. , 2.33333, nan]) y: array([1. , 2.33339, nan]) >>> np.testing.assert_array_almost_equal([1.0,2.33333,np.nan], ... [1.0,2.33333, 5], decimal=5) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 5 decimals x and y nan location mismatch: x: array([1. , 2.33333, nan]) y: array([1. , 2.33333, 5. ]) """ __tracebackhide__ = True # Hide traceback for py.test from numpy.core import number, float_, result_type, array from numpy.core.numerictypes import issubdtype from numpy.core.fromnumeric import any as npany def compare(x, y): try: if npany(gisinf(x)) or npany( gisinf(y)): xinfid = gisinf(x) yinfid = gisinf(y) if not (xinfid == yinfid).all(): return False # if one item, x and y is +- inf if x.size == y.size == 1: return x == y x = x[~xinfid] y = y[~yinfid] except (TypeError, NotImplementedError): pass # make sure y is an inexact type to avoid abs(MIN_INT); will cause # casting of x later. dtype = result_type(y, 1.) y = np.asanyarray(y, dtype) z = abs(x - y) if not issubdtype(z.dtype, number): z = z.astype(float_) # handle object arrays return z < 1.5 * 10.0**(-decimal) > assert_array_compare(compare, x, y, err_msg=err_msg, verbose=verbose, header=('Arrays are not almost equal to %d decimals' % decimal), precision=decimal) miniconda3/envs/myKwant/lib/python3.11/site-packages/numpy/testing/_private/utils.py:1099: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ args = (.compare at 0x13981e340>, array([[17.35003728, 0.83272758, 12.77101887, ..., 8.20972779]]), array([[1., 0., 0., 0.], [0., 1., 0., 0.], [0., 0., 1., 0.], [0., 0., 0., 1.]])) kwds = {'err_msg': '', 'header': 'Arrays are not almost equal to 7 decimals', 'precision': 7, 'verbose': True} @wraps(func) def inner(*args, **kwds): with self._recreate_cm(): > return func(*args, **kwds) miniconda3/envs/myKwant/lib/python3.11/contextlib.py:81: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ comparison = .compare at 0x13981e340> x = array([17.35003728, 0.83272758, 12.77101887, -4.7021894 , 0.83272758, 5.31817007, -3.89030484, -1.75998971, 12.77101887, -3.89030484, 35.55422496, -7.66975788, -4.7021894 , -1.75998971, -7.66975788, 8.20972779]) y = array([1., 0., 0., 0., 0., 1., 0., 0., 0., 0., 1., 0., 0., 0., 0., 1.]) err_msg = '\nMismatched elements: 16 / 16 (100%)\nMax absolute difference: 34.55422496\nMax relative difference: 34.55422496' verbose = True, header = 'Arrays are not almost equal to 7 decimals', precision = 7 equal_nan = True, equal_inf = True @np._no_nep50_warning() def assert_array_compare(comparison, x, y, err_msg='', verbose=True, header='', precision=6, equal_nan=True, equal_inf=True, *, strict=False): __tracebackhide__ = True # Hide traceback for py.test from numpy.core import array, array2string, isnan, inf, bool_, errstate, all, max, object_ x = np.asanyarray(x) y = np.asanyarray(y) # original array for output formatting ox, oy = x, y def isnumber(x): return x.dtype.char in '?bhilqpBHILQPefdgFDG' def istime(x): return x.dtype.char in "Mm" def func_assert_same_pos(x, y, func=isnan, hasval='nan'): """Handling nan/inf. Combine results of running func on x and y, checking that they are True at the same locations. """ __tracebackhide__ = True # Hide traceback for py.test x_id = func(x) y_id = func(y) # We include work-arounds here to handle three types of slightly # pathological ndarray subclasses: # (1) all() on `masked` array scalars can return masked arrays, so we # use != True # (2) __eq__ on some ndarray subclasses returns Python booleans # instead of element-wise comparisons, so we cast to bool_() and # use isinstance(..., bool) checks # (3) subclasses with bare-bones __array_function__ implementations may # not implement np.all(), so favor using the .all() method # We are not committed to supporting such subclasses, but it's nice to # support them if possible. if bool_(x_id == y_id).all() != True: msg = build_err_msg([x, y], err_msg + '\nx and y %s location mismatch:' % (hasval), verbose=verbose, header=header, names=('x', 'y'), precision=precision) raise AssertionError(msg) # If there is a scalar, then here we know the array has the same # flag as it everywhere, so we should return the scalar flag. if isinstance(x_id, bool) or x_id.ndim == 0: return bool_(x_id) elif isinstance(y_id, bool) or y_id.ndim == 0: return bool_(y_id) else: return y_id try: if strict: cond = x.shape == y.shape and x.dtype == y.dtype else: cond = (x.shape == () or y.shape == ()) or x.shape == y.shape if not cond: if x.shape != y.shape: reason = f'\n(shapes {x.shape}, {y.shape} mismatch)' else: reason = f'\n(dtypes {x.dtype}, {y.dtype} mismatch)' msg = build_err_msg([x, y], err_msg + reason, verbose=verbose, header=header, names=('x', 'y'), precision=precision) raise AssertionError(msg) flagged = bool_(False) if isnumber(x) and isnumber(y): if equal_nan: flagged = func_assert_same_pos(x, y, func=isnan, hasval='nan') if equal_inf: flagged |= func_assert_same_pos(x, y, func=lambda xy: xy == +inf, hasval='+inf') flagged |= func_assert_same_pos(x, y, func=lambda xy: xy == -inf, hasval='-inf') elif istime(x) and istime(y): # If one is datetime64 and the other timedelta64 there is no point if equal_nan and x.dtype.type == y.dtype.type: flagged = func_assert_same_pos(x, y, func=isnat, hasval="NaT") if flagged.ndim > 0: x, y = x[~flagged], y[~flagged] # Only do the comparison if actual values are left if x.size == 0: return elif flagged: # no sense doing comparison if everything is flagged. return val = comparison(x, y) if isinstance(val, bool): cond = val reduced = array([val]) else: reduced = val.ravel() cond = reduced.all() # The below comparison is a hack to ensure that fully masked # results, for which val.ravel().all() returns np.ma.masked, # do not trigger a failure (np.ma.masked != True evaluates as # np.ma.masked, which is falsy). if cond != True: n_mismatch = reduced.size - reduced.sum(dtype=intp) n_elements = flagged.size if flagged.ndim != 0 else reduced.size percent_mismatch = 100 * n_mismatch / n_elements remarks = [ 'Mismatched elements: {} / {} ({:.3g}%)'.format( n_mismatch, n_elements, percent_mismatch)] with errstate(all='ignore'): # ignore errors for non-numeric types with contextlib.suppress(TypeError): error = abs(x - y) if np.issubdtype(x.dtype, np.unsignedinteger): error2 = abs(y - x) np.minimum(error, error2, out=error) max_abs_error = max(error) if getattr(error, 'dtype', object_) == object_: remarks.append('Max absolute difference: ' + str(max_abs_error)) else: remarks.append('Max absolute difference: ' + array2string(max_abs_error)) # note: this definition of relative error matches that one # used by assert_allclose (found in np.isclose) # Filter values where the divisor would be zero nonzero = bool_(y != 0) if all(~nonzero): max_rel_error = array(inf) else: max_rel_error = max(error[nonzero] / abs(y[nonzero])) if getattr(error, 'dtype', object_) == object_: remarks.append('Max relative difference: ' + str(max_rel_error)) else: remarks.append('Max relative difference: ' + array2string(max_rel_error)) err_msg += '\n' + '\n'.join(remarks) msg = build_err_msg([ox, oy], err_msg, verbose=verbose, header=header, names=('x', 'y'), precision=precision) > raise AssertionError(msg) E AssertionError: E Arrays are not almost equal to 7 decimals E E Mismatched elements: 16 / 16 (100%) E Max absolute difference: 34.55422496 E Max relative difference: 34.55422496 E x: array([[17.3500373, 0.8327276, 12.7710189, -4.7021894], E [ 0.8327276, 5.3181701, -3.8903048, -1.7599897], E [12.7710189, -3.8903048, 35.554225 , -7.6697579], E [-4.7021894, -1.7599897, -7.6697579, 8.2097278]]) E y: array([[1., 0., 0., 0.], E [0., 1., 0., 0.], E [0., 0., 1., 0.], E [0., 0., 0., 1.]]) miniconda3/envs/myKwant/lib/python3.11/site-packages/numpy/testing/_private/utils.py:862: AssertionError During handling of the above exception, another exception occurred: def test_singular_graph_system(): for opts in opt_list: reset_options() options(**opts) > _test_sparse.test_singular_graph_system(smatrix) miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/test_mumps.py:66: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/_test_sparse.py:252: in test_singular_graph_system assert_almost_equal(np.dot(s.conjugate().transpose(), s), _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ args = (array([[17.35003728-2.10086905e-17j, 0.83272758+3.86226056e-01j, 12.77101887-1.63874544e+01j, -4.7021894 -6....61345408e-17j]]), array([[1., 0., 0., 0.], [0., 1., 0., 0.], [0., 0., 1., 0.], [0., 0., 0., 1.]])) kwds = {} @wraps(func) def inner(*args, **kwds): with self._recreate_cm(): > return func(*args, **kwds) E AssertionError: E Arrays are not almost equal to 7 decimals E ACTUAL: array([[17.35003728-2.10086905e-17j, 0.83272758+3.86226056e-01j, E 12.77101887-1.63874544e+01j, -4.7021894 -6.61464843e-01j], E [ 0.83272758-3.86226056e-01j, 5.31817007-1.23976108e-16j,... E DESIRED: array([[1., 0., 0., 0.], E [0., 1., 0., 0.], E [0., 0., 1., 0.], E [0., 0., 0., 1.]]) miniconda3/envs/myKwant/lib/python3.11/contextlib.py:81: AssertionError ______________________________ test_tricky_singular_hopping ______________________________ actual = array([[156.00696037-2.88614066e-15j, 88.55796228+3.64058430e-13j], [ 88.55796228-3.66911796e-13j, 50.93208119+1.22887499e-15j]]) desired = array([[1., 0.], [0., 1.]]), decimal = 7, err_msg = '', verbose = True @np._no_nep50_warning() def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=True): """ Raises an AssertionError if two items are not equal up to desired precision. .. note:: It is recommended to use one of `assert_allclose`, `assert_array_almost_equal_nulp` or `assert_array_max_ulp` instead of this function for more consistent floating point comparisons. The test verifies that the elements of `actual` and `desired` satisfy. ``abs(desired-actual) < float64(1.5 * 10**(-decimal))`` That is a looser test than originally documented, but agrees with what the actual implementation in `assert_array_almost_equal` did up to rounding vagaries. An exception is raised at conflicting values. For ndarrays this delegates to assert_array_almost_equal Parameters ---------- actual : array_like The object to check. desired : array_like The expected object. decimal : int, optional Desired precision, default is 7. err_msg : str, optional The error message to be printed in case of failure. verbose : bool, optional If True, the conflicting values are appended to the error message. Raises ------ AssertionError If actual and desired are not equal up to specified precision. See Also -------- assert_allclose: Compare two array_like objects for equality with desired relative and/or absolute precision. assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal Examples -------- >>> from numpy.testing import assert_almost_equal >>> assert_almost_equal(2.3333333333333, 2.33333334) >>> assert_almost_equal(2.3333333333333, 2.33333334, decimal=10) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 10 decimals ACTUAL: 2.3333333333333 DESIRED: 2.33333334 >>> assert_almost_equal(np.array([1.0,2.3333333333333]), ... np.array([1.0,2.33333334]), decimal=9) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 9 decimals Mismatched elements: 1 / 2 (50%) Max absolute difference: 6.66669964e-09 Max relative difference: 2.85715698e-09 x: array([1. , 2.333333333]) y: array([1. , 2.33333334]) """ __tracebackhide__ = True # Hide traceback for py.test from numpy.core import ndarray from numpy.lib import iscomplexobj, real, imag # Handle complex numbers: separate into real/imag to handle # nan/inf/negative zero correctly # XXX: catch ValueError for subclasses of ndarray where iscomplex fail try: usecomplex = iscomplexobj(actual) or iscomplexobj(desired) except ValueError: usecomplex = False def _build_err_msg(): header = ('Arrays are not almost equal to %d decimals' % decimal) return build_err_msg([actual, desired], err_msg, verbose=verbose, header=header) if usecomplex: if iscomplexobj(actual): actualr = real(actual) actuali = imag(actual) else: actualr = actual actuali = 0 if iscomplexobj(desired): desiredr = real(desired) desiredi = imag(desired) else: desiredr = desired desiredi = 0 try: > assert_almost_equal(actualr, desiredr, decimal=decimal) miniconda3/envs/myKwant/lib/python3.11/site-packages/numpy/testing/_private/utils.py:581: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ args = (array([[156.00696037, 88.55796228], [ 88.55796228, 50.93208119]]), array([[1., 0.], [0., 1.]])) kwds = {'decimal': 7} @wraps(func) def inner(*args, **kwds): with self._recreate_cm(): > return func(*args, **kwds) miniconda3/envs/myKwant/lib/python3.11/contextlib.py:81: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ actual = array([[156.00696037, 88.55796228], [ 88.55796228, 50.93208119]]) desired = array([[1., 0.], [0., 1.]]), decimal = 7, err_msg = '', verbose = True @np._no_nep50_warning() def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=True): """ Raises an AssertionError if two items are not equal up to desired precision. .. note:: It is recommended to use one of `assert_allclose`, `assert_array_almost_equal_nulp` or `assert_array_max_ulp` instead of this function for more consistent floating point comparisons. The test verifies that the elements of `actual` and `desired` satisfy. ``abs(desired-actual) < float64(1.5 * 10**(-decimal))`` That is a looser test than originally documented, but agrees with what the actual implementation in `assert_array_almost_equal` did up to rounding vagaries. An exception is raised at conflicting values. For ndarrays this delegates to assert_array_almost_equal Parameters ---------- actual : array_like The object to check. desired : array_like The expected object. decimal : int, optional Desired precision, default is 7. err_msg : str, optional The error message to be printed in case of failure. verbose : bool, optional If True, the conflicting values are appended to the error message. Raises ------ AssertionError If actual and desired are not equal up to specified precision. See Also -------- assert_allclose: Compare two array_like objects for equality with desired relative and/or absolute precision. assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal Examples -------- >>> from numpy.testing import assert_almost_equal >>> assert_almost_equal(2.3333333333333, 2.33333334) >>> assert_almost_equal(2.3333333333333, 2.33333334, decimal=10) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 10 decimals ACTUAL: 2.3333333333333 DESIRED: 2.33333334 >>> assert_almost_equal(np.array([1.0,2.3333333333333]), ... np.array([1.0,2.33333334]), decimal=9) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 9 decimals Mismatched elements: 1 / 2 (50%) Max absolute difference: 6.66669964e-09 Max relative difference: 2.85715698e-09 x: array([1. , 2.333333333]) y: array([1. , 2.33333334]) """ __tracebackhide__ = True # Hide traceback for py.test from numpy.core import ndarray from numpy.lib import iscomplexobj, real, imag # Handle complex numbers: separate into real/imag to handle # nan/inf/negative zero correctly # XXX: catch ValueError for subclasses of ndarray where iscomplex fail try: usecomplex = iscomplexobj(actual) or iscomplexobj(desired) except ValueError: usecomplex = False def _build_err_msg(): header = ('Arrays are not almost equal to %d decimals' % decimal) return build_err_msg([actual, desired], err_msg, verbose=verbose, header=header) if usecomplex: if iscomplexobj(actual): actualr = real(actual) actuali = imag(actual) else: actualr = actual actuali = 0 if iscomplexobj(desired): desiredr = real(desired) desiredi = imag(desired) else: desiredr = desired desiredi = 0 try: assert_almost_equal(actualr, desiredr, decimal=decimal) assert_almost_equal(actuali, desiredi, decimal=decimal) except AssertionError: raise AssertionError(_build_err_msg()) if isinstance(actual, (ndarray, tuple, list)) \ or isinstance(desired, (ndarray, tuple, list)): > return assert_array_almost_equal(actual, desired, decimal, err_msg) miniconda3/envs/myKwant/lib/python3.11/site-packages/numpy/testing/_private/utils.py:588: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ args = (array([[156.00696037, 88.55796228], [ 88.55796228, 50.93208119]]), array([[1., 0.], [0., 1.]]), 7, '') kwds = {} @wraps(func) def inner(*args, **kwds): with self._recreate_cm(): > return func(*args, **kwds) miniconda3/envs/myKwant/lib/python3.11/contextlib.py:81: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ x = array([[156.00696037, 88.55796228], [ 88.55796228, 50.93208119]]) y = array([[1., 0.], [0., 1.]]), decimal = 7, err_msg = '', verbose = True @np._no_nep50_warning() def assert_array_almost_equal(x, y, decimal=6, err_msg='', verbose=True): """ Raises an AssertionError if two objects are not equal up to desired precision. .. note:: It is recommended to use one of `assert_allclose`, `assert_array_almost_equal_nulp` or `assert_array_max_ulp` instead of this function for more consistent floating point comparisons. The test verifies identical shapes and that the elements of ``actual`` and ``desired`` satisfy. ``abs(desired-actual) < 1.5 * 10**(-decimal)`` That is a looser test than originally documented, but agrees with what the actual implementation did up to rounding vagaries. An exception is raised at shape mismatch or conflicting values. In contrast to the standard usage in numpy, NaNs are compared like numbers, no assertion is raised if both objects have NaNs in the same positions. Parameters ---------- x : array_like The actual object to check. y : array_like The desired, expected object. decimal : int, optional Desired precision, default is 6. err_msg : str, optional The error message to be printed in case of failure. verbose : bool, optional If True, the conflicting values are appended to the error message. Raises ------ AssertionError If actual and desired are not equal up to specified precision. See Also -------- assert_allclose: Compare two array_like objects for equality with desired relative and/or absolute precision. assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal Examples -------- the first assert does not raise an exception >>> np.testing.assert_array_almost_equal([1.0,2.333,np.nan], ... [1.0,2.333,np.nan]) >>> np.testing.assert_array_almost_equal([1.0,2.33333,np.nan], ... [1.0,2.33339,np.nan], decimal=5) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 5 decimals Mismatched elements: 1 / 3 (33.3%) Max absolute difference: 6.e-05 Max relative difference: 2.57136612e-05 x: array([1. , 2.33333, nan]) y: array([1. , 2.33339, nan]) >>> np.testing.assert_array_almost_equal([1.0,2.33333,np.nan], ... [1.0,2.33333, 5], decimal=5) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 5 decimals x and y nan location mismatch: x: array([1. , 2.33333, nan]) y: array([1. , 2.33333, 5. ]) """ __tracebackhide__ = True # Hide traceback for py.test from numpy.core import number, float_, result_type, array from numpy.core.numerictypes import issubdtype from numpy.core.fromnumeric import any as npany def compare(x, y): try: if npany(gisinf(x)) or npany( gisinf(y)): xinfid = gisinf(x) yinfid = gisinf(y) if not (xinfid == yinfid).all(): return False # if one item, x and y is +- inf if x.size == y.size == 1: return x == y x = x[~xinfid] y = y[~yinfid] except (TypeError, NotImplementedError): pass # make sure y is an inexact type to avoid abs(MIN_INT); will cause # casting of x later. dtype = result_type(y, 1.) y = np.asanyarray(y, dtype) z = abs(x - y) if not issubdtype(z.dtype, number): z = z.astype(float_) # handle object arrays return z < 1.5 * 10.0**(-decimal) > assert_array_compare(compare, x, y, err_msg=err_msg, verbose=verbose, header=('Arrays are not almost equal to %d decimals' % decimal), precision=decimal) miniconda3/envs/myKwant/lib/python3.11/site-packages/numpy/testing/_private/utils.py:1099: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ args = (.compare at 0x139a3a020>, array([[156.00696037, 88.55796228], [ 88.55796228, 50.93208119]]), array([[1., 0.], [0., 1.]])) kwds = {'err_msg': '', 'header': 'Arrays are not almost equal to 7 decimals', 'precision': 7, 'verbose': True} @wraps(func) def inner(*args, **kwds): with self._recreate_cm(): > return func(*args, **kwds) miniconda3/envs/myKwant/lib/python3.11/contextlib.py:81: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ comparison = .compare at 0x139a3a020> x = array([156.00696037, 88.55796228, 88.55796228, 50.93208119]) y = array([1., 0., 0., 1.]) err_msg = '\nMismatched elements: 4 / 4 (100%)\nMax absolute difference: 155.00696037\nMax relative difference: 155.00696037' verbose = True, header = 'Arrays are not almost equal to 7 decimals', precision = 7 equal_nan = True, equal_inf = True @np._no_nep50_warning() def assert_array_compare(comparison, x, y, err_msg='', verbose=True, header='', precision=6, equal_nan=True, equal_inf=True, *, strict=False): __tracebackhide__ = True # Hide traceback for py.test from numpy.core import array, array2string, isnan, inf, bool_, errstate, all, max, object_ x = np.asanyarray(x) y = np.asanyarray(y) # original array for output formatting ox, oy = x, y def isnumber(x): return x.dtype.char in '?bhilqpBHILQPefdgFDG' def istime(x): return x.dtype.char in "Mm" def func_assert_same_pos(x, y, func=isnan, hasval='nan'): """Handling nan/inf. Combine results of running func on x and y, checking that they are True at the same locations. """ __tracebackhide__ = True # Hide traceback for py.test x_id = func(x) y_id = func(y) # We include work-arounds here to handle three types of slightly # pathological ndarray subclasses: # (1) all() on `masked` array scalars can return masked arrays, so we # use != True # (2) __eq__ on some ndarray subclasses returns Python booleans # instead of element-wise comparisons, so we cast to bool_() and # use isinstance(..., bool) checks # (3) subclasses with bare-bones __array_function__ implementations may # not implement np.all(), so favor using the .all() method # We are not committed to supporting such subclasses, but it's nice to # support them if possible. if bool_(x_id == y_id).all() != True: msg = build_err_msg([x, y], err_msg + '\nx and y %s location mismatch:' % (hasval), verbose=verbose, header=header, names=('x', 'y'), precision=precision) raise AssertionError(msg) # If there is a scalar, then here we know the array has the same # flag as it everywhere, so we should return the scalar flag. if isinstance(x_id, bool) or x_id.ndim == 0: return bool_(x_id) elif isinstance(y_id, bool) or y_id.ndim == 0: return bool_(y_id) else: return y_id try: if strict: cond = x.shape == y.shape and x.dtype == y.dtype else: cond = (x.shape == () or y.shape == ()) or x.shape == y.shape if not cond: if x.shape != y.shape: reason = f'\n(shapes {x.shape}, {y.shape} mismatch)' else: reason = f'\n(dtypes {x.dtype}, {y.dtype} mismatch)' msg = build_err_msg([x, y], err_msg + reason, verbose=verbose, header=header, names=('x', 'y'), precision=precision) raise AssertionError(msg) flagged = bool_(False) if isnumber(x) and isnumber(y): if equal_nan: flagged = func_assert_same_pos(x, y, func=isnan, hasval='nan') if equal_inf: flagged |= func_assert_same_pos(x, y, func=lambda xy: xy == +inf, hasval='+inf') flagged |= func_assert_same_pos(x, y, func=lambda xy: xy == -inf, hasval='-inf') elif istime(x) and istime(y): # If one is datetime64 and the other timedelta64 there is no point if equal_nan and x.dtype.type == y.dtype.type: flagged = func_assert_same_pos(x, y, func=isnat, hasval="NaT") if flagged.ndim > 0: x, y = x[~flagged], y[~flagged] # Only do the comparison if actual values are left if x.size == 0: return elif flagged: # no sense doing comparison if everything is flagged. return val = comparison(x, y) if isinstance(val, bool): cond = val reduced = array([val]) else: reduced = val.ravel() cond = reduced.all() # The below comparison is a hack to ensure that fully masked # results, for which val.ravel().all() returns np.ma.masked, # do not trigger a failure (np.ma.masked != True evaluates as # np.ma.masked, which is falsy). if cond != True: n_mismatch = reduced.size - reduced.sum(dtype=intp) n_elements = flagged.size if flagged.ndim != 0 else reduced.size percent_mismatch = 100 * n_mismatch / n_elements remarks = [ 'Mismatched elements: {} / {} ({:.3g}%)'.format( n_mismatch, n_elements, percent_mismatch)] with errstate(all='ignore'): # ignore errors for non-numeric types with contextlib.suppress(TypeError): error = abs(x - y) if np.issubdtype(x.dtype, np.unsignedinteger): error2 = abs(y - x) np.minimum(error, error2, out=error) max_abs_error = max(error) if getattr(error, 'dtype', object_) == object_: remarks.append('Max absolute difference: ' + str(max_abs_error)) else: remarks.append('Max absolute difference: ' + array2string(max_abs_error)) # note: this definition of relative error matches that one # used by assert_allclose (found in np.isclose) # Filter values where the divisor would be zero nonzero = bool_(y != 0) if all(~nonzero): max_rel_error = array(inf) else: max_rel_error = max(error[nonzero] / abs(y[nonzero])) if getattr(error, 'dtype', object_) == object_: remarks.append('Max relative difference: ' + str(max_rel_error)) else: remarks.append('Max relative difference: ' + array2string(max_rel_error)) err_msg += '\n' + '\n'.join(remarks) msg = build_err_msg([ox, oy], err_msg, verbose=verbose, header=header, names=('x', 'y'), precision=precision) > raise AssertionError(msg) E AssertionError: E Arrays are not almost equal to 7 decimals E E Mismatched elements: 4 / 4 (100%) E Max absolute difference: 155.00696037 E Max relative difference: 155.00696037 E x: array([[156.0069604, 88.5579623], E [ 88.5579623, 50.9320812]]) E y: array([[1., 0.], E [0., 1.]]) miniconda3/envs/myKwant/lib/python3.11/site-packages/numpy/testing/_private/utils.py:862: AssertionError During handling of the above exception, another exception occurred: def test_tricky_singular_hopping(): for opts in opt_list: reset_options() options(**opts) > _test_sparse.test_tricky_singular_hopping(smatrix) miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/test_mumps.py:73: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/_test_sparse.py:290: in test_tricky_singular_hopping assert_almost_equal(np.dot(s.conjugate().transpose(), s), _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ args = (array([[156.00696037-2.88614066e-15j, 88.55796228+3.64058430e-13j], [ 88.55796228-3.66911796e-13j, 50.93208119+1.22887499e-15j]]), array([[1., 0.], [0., 1.]])) kwds = {} @wraps(func) def inner(*args, **kwds): with self._recreate_cm(): > return func(*args, **kwds) E AssertionError: E Arrays are not almost equal to 7 decimals E ACTUAL: array([[156.00696037-2.88614066e-15j, 88.55796228+3.64058430e-13j], E [ 88.55796228-3.66911796e-13j, 50.93208119+1.22887499e-15j]]) E DESIRED: array([[1., 0.], E [0., 1.]]) miniconda3/envs/myKwant/lib/python3.11/contextlib.py:81: AssertionError ____________________________________ test_many_leads _____________________________________ def test_many_leads(): for opts in opt_list: reset_options() options(**opts) > _test_sparse.test_many_leads(greens_function, smatrix) miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/test_mumps.py:80: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/_test_sparse.py:324: in test_many_leads assert_almost_equal(cmat.sum(axis=1), [0] * 4) miniconda3/envs/myKwant/lib/python3.11/contextlib.py:81: in inner return func(*args, **kwds) miniconda3/envs/myKwant/lib/python3.11/contextlib.py:81: in inner return func(*args, **kwds) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ args = (.compare at 0x139a3a5c0>, array([ 0.04236524, -0.22275334, 0.22540983, -0.04502173]), [0, 0, 0, 0]) kwds = {'err_msg': '', 'header': 'Arrays are not almost equal to 7 decimals', 'precision': 7, 'verbose': True} @wraps(func) def inner(*args, **kwds): with self._recreate_cm(): > return func(*args, **kwds) E AssertionError: E Arrays are not almost equal to 7 decimals E E Mismatched elements: 4 / 4 (100%) E Max absolute difference: 0.22540983 E Max relative difference: inf E x: array([ 0.0423652, -0.2227533, 0.2254098, -0.0450217]) E y: array([0, 0, 0, 0]) miniconda3/envs/myKwant/lib/python3.11/contextlib.py:81: AssertionError ____________________________________ test_selfenergy _____________________________________ def test_selfenergy(): for opts in opt_list: reset_options() options(**opts) > _test_sparse.test_selfenergy(greens_function, smatrix) miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/test_mumps.py:87: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/_test_sparse.py:386: in test_selfenergy check_fsyst(fsyst) miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/_test_sparse.py:381: in check_fsyst assert_almost_equal(np.sort(eig_are.real)[-n_eig:], miniconda3/envs/myKwant/lib/python3.11/contextlib.py:81: in inner return func(*args, **kwds) miniconda3/envs/myKwant/lib/python3.11/contextlib.py:81: in inner return func(*args, **kwds) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ args = (.compare at 0x139a38040>, array([1.31374196e-14, 1.67570429e+01]), array([6.76352364e-16, 9.31534610e+00])) kwds = {'err_msg': '', 'header': 'Arrays are not almost equal to 7 decimals', 'precision': 7, 'verbose': True} @wraps(func) def inner(*args, **kwds): with self._recreate_cm(): > return func(*args, **kwds) E AssertionError: E Arrays are not almost equal to 7 decimals E E Mismatched elements: 1 / 2 (50%) E Max absolute difference: 7.44169679 E Max relative difference: 18.42392804 E x: array([1.3137420e-14, 1.6757043e+01]) E y: array([6.7635236e-16, 9.3153461e+00]) miniconda3/envs/myKwant/lib/python3.11/contextlib.py:81: AssertionError _______________________________ test_selfenergy_reflection _______________________________ def test_selfenergy_reflection(): for opts in opt_list: reset_options() options(**opts) > _test_sparse.test_selfenergy_reflection(greens_function, smatrix) miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/test_mumps.py:94: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/_test_sparse.py:418: in test_selfenergy_reflection assert_almost_equal(sol.transmission(0,0), t.transmission(0,0)) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ args = (512.7020895881353, 49.604613947074036), kwds = {} @wraps(func) def inner(*args, **kwds): with self._recreate_cm(): > return func(*args, **kwds) E AssertionError: E Arrays are not almost equal to 7 decimals E ACTUAL: 512.7020895881353 E DESIRED: 49.604613947074036 miniconda3/envs/myKwant/lib/python3.11/contextlib.py:81: AssertionError _______________________________________ test_ldos ________________________________________ def test_ldos(): for opts in opt_list: reset_options() options(**opts) > _test_sparse.test_ldos(ldos) miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/test_mumps.py:108: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/_test_sparse.py:456: in test_ldos assert_almost_equal(ldos(finsyst, 0), miniconda3/envs/myKwant/lib/python3.11/contextlib.py:81: in inner return func(*args, **kwds) miniconda3/envs/myKwant/lib/python3.11/contextlib.py:81: in inner return func(*args, **kwds) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ args = (.compare at 0x139a3bce0>, array([0.03978874, 0.03978874]), array([0.15915494, 0.15915494])) kwds = {'err_msg': '', 'header': 'Arrays are not almost equal to 7 decimals', 'precision': 7, 'verbose': True} @wraps(func) def inner(*args, **kwds): with self._recreate_cm(): > return func(*args, **kwds) E AssertionError: E Arrays are not almost equal to 7 decimals E E Mismatched elements: 2 / 2 (100%) E Max absolute difference: 0.11936621 E Max relative difference: 0.75 E x: array([0.0397887, 0.0397887]) E y: array([0.1591549, 0.1591549]) miniconda3/envs/myKwant/lib/python3.11/contextlib.py:81: AssertionError ___________________________ test_ModesLead_and_SelfEnergyLead ____________________________ def test_ModesLead_and_SelfEnergyLead(): lat = builder.SimpleSiteFamily() hoppings = [builder.HoppingKind((1, 0), lat), builder.HoppingKind((0, 1), lat)] rng = Random(123) L = 5 t = 1 energies = [0.9, 1.7] syst = builder.Builder() for x in range(L): for y in range(L): syst[lat(x, y)] = 4 * t + rng.random() - 0.5 syst[hoppings] = -t # Attach a lead from the left. lead = builder.Builder(VerySimpleSymmetry(-1)) for y in range(L): lead[lat(0, y)] = 4 * t lead[hoppings] = -t syst.attach_lead(lead) # Make the right lead and attach it. lead = builder.Builder(VerySimpleSymmetry(1)) for y in range(L): lead[lat(0, y)] = 4 * t lead[hoppings] = -t syst.attach_lead(lead) fsyst = syst.finalized() ts = [kwant.smatrix(fsyst, e).transmission(1, 0) for e in energies] # Replace lead with it's finalized copy. lead = fsyst.leads[1] interface = [lat(L-1, lead.sites[i].tag[1]) for i in range(L)] # Re-attach right lead as ModesLead. syst.leads[1] = builder.ModesLead(lead.modes, interface, lead.parameters) fsyst = syst.finalized() ts2 = [kwant.smatrix(fsyst, e).transmission(1, 0) for e in energies] assert_almost_equal(ts2, ts) # Re-attach right lead as ModesLead with old-style modes API # that does not take a 'params' keyword parameter. syst.leads[1] = builder.ModesLead( lambda energy, args: lead.modes(energy, args), interface, lead.parameters) fsyst = syst.finalized() ts2 = [kwant.smatrix(fsyst, e).transmission(1, 0) for e in energies] assert_almost_equal(ts2, ts) # Re-attach right lead as SelfEnergyLead. syst.leads[1] = builder.SelfEnergyLead(lead.selfenergy, interface, lead.parameters) fsyst = syst.finalized() ts2 = [kwant.greens_function(fsyst, e).transmission(1, 0) for e in energies] > assert_almost_equal(ts2, ts) miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_builder.py:1131: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ miniconda3/envs/myKwant/lib/python3.11/contextlib.py:81: in inner return func(*args, **kwds) miniconda3/envs/myKwant/lib/python3.11/contextlib.py:81: in inner return func(*args, **kwds) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ args = (.compare at 0x139ad5080>, [1.522264137460186, 14.24377520296762], [0.3215344398371684, 1.5762424380581528]) kwds = {'err_msg': '', 'header': 'Arrays are not almost equal to 7 decimals', 'precision': 7, 'verbose': True} @wraps(func) def inner(*args, **kwds): with self._recreate_cm(): > return func(*args, **kwds) E AssertionError: E Arrays are not almost equal to 7 decimals E E Mismatched elements: 2 / 2 (100%) E Max absolute difference: 12.66753276 E Max relative difference: 8.03653833 E x: array([ 1.5222641, 14.2437752]) E y: array([0.3215344, 1.5762424]) miniconda3/envs/myKwant/lib/python3.11/contextlib.py:81: AssertionError ________________________________________ test_qhe ________________________________________ W = 16, L = 8 def test_qhe(W=16, L=8): def central_region(pos): x, y = pos return -L < x < L and abs(y) < W - 5.5 * math.exp(-x**2 / 5**2) lat = kwant.lattice.square() syst = kwant.Builder() syst[lat.shape(central_region, (0, 0))] = onsite syst[lat.neighbors()] = hopping lead = kwant.Builder(kwant.TranslationalSymmetry((-1, 0))) lead[(lat(0, y) for y in range(-W + 1, W))] = 4 lead[lat.neighbors()] = hopping syst.attach_lead(lead) syst.attach_lead(lead.reversed()) syst = syst.finalized() #### The following chunk of code can be uncommented to visualize the #### conductance plateaus. # from matplotlib import pyplot # import numpy # reciprocal_phis = numpy.linspace(0.1, 7, 200) # conductances = [] # for phi in 1 / reciprocal_phis: # smatrix = kwant.smatrix(syst, 1.0, [phi, ""]) # conductances.append(smatrix.transmission(1, 0)) # pyplot.plot(reciprocal_phis, conductances) # pyplot.show() for r_phis, T_nominal, max_err in [((1.3, 2.1), 1, 1e-7), ((3.2, 3.7), 2, 1e-3), ((5.2, 5.5), 3, 1e-1)]: for r_phi in r_phis: params = dict(phi=1.0 / r_phi, salt="") pc = syst.precalculate(1.0, params=params, what='all') for result in [kwant.smatrix(pc, 1, params=params), kwant.solvers.default.greens_function(pc, 1, params=params)]: > assert abs(T_nominal - result.transmission(1, 0)) < max_err E assert 52.26315327726159 < 1e-07 E + where 52.26315327726159 = abs((1 - 53.26315327726159)) E + where 53.26315327726159 = , ], out_leads=[0, 1], in_leads=[0, 1])>(1, 0) E + where , ], out_leads=[0, 1], in_leads=[0, 1])> = SMatrix(data=array([[5.05289108+2.39517701j, 0.07685137-0.02731875j],\n [6.61848483+3.07551814j, 0.14714141-0.03302529j]]), lead_info=[, ], out_leads=[0, 1], in_leads=[0, 1]).transmission miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_comprehensive.py:55: AssertionError ______________________________ test_opservables_scattering _______________________________ def test_opservables_scattering(): # Disordered system with two ordered strips on the left/right. We check # that the current on the right of the disorder due to incoming mode `m` is # equal to ��_n |t_nm|^2. Similarly the current on the left of the disorder # is checked against 1 - ��_n |r_nm|^2 N = 10 lat, syst = _random_square_system(N) # add extra sites so we can calculate the current in a region # where there is no backscattering syst[(lat(i, j) for i in [-1, N] for j in range(N))] = 2 syst[((lat(-1, j), lat(0, j)) for j in range(N))] = -1 syst[((lat(N-1, j), lat(N, j)) for j in range(N))] = -1 lat, lead = _perfect_lead(3) syst.attach_lead(lead) syst.attach_lead(lead.reversed()) fsyst = syst.finalized() # currents on the left and right of the disordered region right_interface = [(lat(N, j), lat(N-1, j)) for j in range(3)] left_interface = [(lat(0, j), lat(-1, j)) for j in range(3)] J_right = ops.Current(fsyst, where=right_interface) J_right_tot = ops.Current(fsyst, where=right_interface, sum=True) J_left = ops.Current(fsyst, where=left_interface) J_left_tot = ops.Current(fsyst, where=left_interface, sum=True) smatrix = kwant.smatrix(fsyst, energy=1.0) t = smatrix.submatrix(1, 0).T # want to iterate over the columns r = smatrix.submatrix(0, 0).T # want to iterate over the columns wfs = kwant.wave_function(fsyst, energy=1.0)(0) for rv, tv, wf in zip(r, t, wfs): > _test(J_right, wf, reduced_val=np.sum(np.abs(tv)**2)) miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_operator.py:281: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ A = bra = array([ 0.76255988+0.76255988j, -0.31116924-0.31116924j, 0.63360607+0.63360607j, 0.15419775+0.15419775j, ...73j, -0.0113682 -0.0113682j , 0.09822374+0.09822374j, 0.01899566+0.01899566j, -0.11424602-0.11424602j]) ket = array([ 0.76255988+0.76255988j, -0.31116924-0.31116924j, 0.63360607+0.63360607j, 0.15419775+0.15419775j, ...73j, -0.0113682 -0.0113682j , 0.09822374+0.09822374j, 0.01899566+0.01899566j, -0.11424602-0.11424602j]) per_el_val = None, reduced_val = 0.003883267589770642, params = None def _test(A, bra, ket=None, per_el_val=None, reduced_val=None, params=None): if per_el_val is not None: val = A(bra, ket, params=params) assert np.allclose(val, per_el_val) # with bound args val = A.bind(params=params)(bra, ket) assert np.allclose(val, per_el_val) # test that inner products give the same thing ket = bra if ket is None else ket act_val = np.dot(bra.conj(), A.act(ket, params=params)) inner_val = np.sum(A(bra, ket, params=params)) # check also when sum is done internally by operator try: sum_reset = A.sum A.sum = True sum_inner_val = A(bra, ket, params=params) assert inner_val == sum_inner_val finally: A.sum = sum_reset assert np.isclose(act_val, inner_val) assert np.isclose(sum_inner_val, inner_val) if reduced_val is not None: > assert np.isclose(inner_val, reduced_val) E assert False E + where False = (-2.1583878590563811e-19, 0.003883267589770642) E + where = np.isclose miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_operator.py:182: AssertionError _________________________________ test_opservables_spin __________________________________ def test_opservables_spin(): def onsite(site, B): return 2 * np.eye(2) + B * sigmaz L = 20 lat = kwant.lattice.chain(norbs=2) syst = kwant.Builder() syst[(lat(i) for i in range(L))] = onsite syst[lat.neighbors()] = -1 * np.eye(2) lead = kwant.Builder(kwant.TranslationalSymmetry((-1,))) lead[lat(0)] = onsite lead[lat.neighbors()] = -1 * np.eye(2) syst.attach_lead(lead) syst.attach_lead(lead.reversed()) fsyst = syst.finalized() params = dict(B=0.1) down, up = kwant.wave_function(fsyst, energy=1., params=params)(0) x_hoppings = kwant.builder.HoppingKind((1,), lat) spin_current_z = ops.Current(fsyst, sigmaz, where=x_hoppings(syst)) > _test(spin_current_z, up, params=params, per_el_val=1) miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_operator.py:308: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ A = bra = array([-0.87238706-0.87238706j, 0. +0.j , -0.62037883-0.62037883j, -0. +0.j , ... , -0.28153304-0.28153304j, 0. +0.j , -0.85862803-0.85862803j, 0. +0.j ]) ket = None, per_el_val = 1, reduced_val = None, params = {'B': 0.1} def _test(A, bra, ket=None, per_el_val=None, reduced_val=None, params=None): if per_el_val is not None: val = A(bra, ket, params=params) > assert np.allclose(val, per_el_val) E assert False E + where False = (array([ 6.90365159e-16, -1.46008772e-16, -1.71486579e-16, -1.34789007e-16,\n 5.51116368e-17, 6.04406794e-17, 9.16042590e-18, -1.42575057e-16,\n -1.53250741e-16, 2.06116588e-16, 3.09174882e-16, 3.19818809e-16,\n 3.62968170e-16, 2.09239661e-16, 2.27798521e-16, -1.99481229e-16,\n 6.53479177e-17, -8.83357229e-17, 1.78593587e-16]), 1) E + where = np.allclose miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_operator.py:162: AssertionError ________________________________ test_opservables_gauged _________________________________ def test_opservables_gauged(): # Test that we get the same answer when we apply a random # gauge (unitary) transformation to each site. We also # adjust our definition of the current to match # this is to get round a bug in test_mask_interpolate (?!) that fails when # the random number state is altered. @contextmanager def save_random_state(): old_state = np.random.get_state() yield np.random.set_state(old_state) L = 20 with save_random_state(): Us = deque([kwant.rmt.circular(2) for i in range(L)]) # need these to get the coupling to the leads right Us.append(np.eye(2)) Us.appendleft(np.eye(2)) H0 = 2 * np.eye(2) + 0.1 * sigmaz # onsite V0 = -1 * np.eye(2) # hopping lat = kwant.lattice.chain(norbs=2) syst = kwant.Builder() for i, U in enumerate(Us): syst[lat(i)] = ft.reduce(np.dot, (U, H0, U.conjugate().transpose())) for a, b in kwant.builder.HoppingKind((1,), lat)(syst): i, j = a.tag[0], b.tag[0] syst[(a, b)] = ft.reduce(np.dot, (Us[i], V0, Us[j].conjugate().transpose())) lead = kwant.Builder(kwant.TranslationalSymmetry((-1,))) lead[lat(0)] = H0 lead[lat.neighbors()] = V0 syst.attach_lead(lead) syst.attach_lead(lead.reversed()) fsyst = syst.finalized() down, up = kwant.wave_function(fsyst, energy=1.0)(0) def M_a(site): i = site.tag[0] return ft.reduce(np.dot, (Us[i], sigmaz, Us[i].conjugate().transpose())) x_hoppings = kwant.builder.HoppingKind((1,), lat) spin_current_gauge = ops.Current(fsyst, M_a, where=x_hoppings(syst)) > _test(spin_current_gauge, up, per_el_val=1) miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_operator.py:370: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ A = bra = array([ 12.71959067+12.71959067j, -4.12852308 -4.12852308j, -5.18112917 -5.18112917j, 5.95103184 +5.9510318... 2.25522641 +2.25522641j, -4.88948449 -4.88948449j, 2.05758 +2.05758j , -4.21447672 -4.21447672j]) ket = None, per_el_val = 1, reduced_val = None, params = None def _test(A, bra, ket=None, per_el_val=None, reduced_val=None, params=None): if per_el_val is not None: val = A(bra, ket, params=params) > assert np.allclose(val, per_el_val) E assert False E + where False = (array([ 282.77140086, 305.15895143, 161.24241779, -214.72578248,\n 83.59490541, 62.53434702, 37.95897866, -1288.43679882,\n -1813.12836596, 33.63312237, 304.0434643 , 95.27104744,\n -424.51338467, 395.9887507 , 110.02495355, 62.69654708,\n 2.28005212, 54.59325001, 72.15506253, 59.88621255,\n 93.54177738]), 1) E + where = np.allclose miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_operator.py:162: AssertionError _______________________________ test_current_interpolation _______________________________ def test_current_interpolation(): ## Passing a Builder will raise an error pytest.raises(TypeError, plotter.interpolate_current, syst_2d(), None) def R(theta): return ta.array([[cos(theta), -sin(theta)], [sin(theta), cos(theta)]]) def make_lattice(a, theta): x = ta.dot(R(theta), (a, 0)) y = ta.dot(R(theta), (0, a)) return kwant.lattice.general([x, y], norbs=1) _test_border_0(plotter.interpolate_current) ## Check current through cross section is same for different lattice ## parameters and orientations of the system wrt. the discretization grid for a, theta, width in [(1, 0, 1), (1, 0, 0.5), (2, 0, 1), (1, 0.2, 1), (2, 0.4, 1)]: lat = make_lattice(a, theta) syst = syst_rect(lat, salt='0').finalized() psi = kwant.wave_function(syst, energy=3)(0) def cut(a, b): return b.tag[0] < 0 and a.tag[0] >= 0 J = kwant.operator.Current(syst).bind() J_cut = kwant.operator.Current(syst, where=cut, sum=True).bind() J_exact = J_cut(psi[0]) data = [] for n in [4, 6, 8, 11, 16]: j0, box = plotter.interpolate_current(syst, J(psi[0]), n=n, abswidth=width) x, y = (np.linspace(mn, mx, shape) for (mn, mx), shape in zip(box, j0.shape)) # slice field perpendicular to a cut along the y axis y_axis = (np.argmin(np.abs(x)), slice(None), 0) J_interp = scipy.integrate.simps(j0[y_axis], y) data.append((n, abs(J_interp - J_exact))) # 3rd value returned from 'linregress' is 'rvalue' # TODO: review this value once #280 has been dealt with. > assert scipy.stats.linregress(np.log(data))[2] < -0.7 E assert 0.9857290648385542 < -0.7 miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_plotter.py:486: AssertionError ==================================== warnings summary ==================================== miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/sparse.py:16 /Users/faruk/miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/sparse.py:16: DeprecationWarning: The module `scipy.sparse.linalg.dsolve.linsolve` is deprecated. All public names must be imported directly from the `scipy.sparse.linalg` namespace. from scipy.sparse.linalg.dsolve import linsolve miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_plotter.py::test_plot /Users/faruk/miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_plotter.py:127: RuntimeWarning: Kwant's plotting functions have the side effect of selecting the matplotlib backend. To avoid this warning, import matplotlib.pyplot, matplotlib.backends or call matplotlib.use(). fig = plot(syst, site_color=color, cmap='binary', file=out) miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_plotter.py::test_current /Users/faruk/miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_plotter.py:540: MatplotlibDeprecationWarning: The get_cmap function was deprecated in Matplotlib 3.7 and will be removed two minor releases later. Use ``matplotlib.colormaps[name]`` or ``matplotlib.colormaps.get_cmap(obj)`` instead. plotter.current(syst, current, file=out) miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_plotter.py::test_current /Users/faruk/miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_plotter.py:544: MatplotlibDeprecationWarning: The get_cmap function was deprecated in Matplotlib 3.7 and will be removed two minor releases later. Use ``matplotlib.colormaps[name]`` or ``matplotlib.colormaps.get_cmap(obj)`` instead. plotter.current(syst, current, ax=ax, file=out) -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html ================================ short test summary info ================================= FAILED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/linalg/tests/test_mumps.py::test_lu_with_dense - AssertionError: FAILED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_uniform_magnetic_field[0] - AssertionError: assert False FAILED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_uniform_magnetic_field[0.1] - AssertionError: assert False FAILED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_uniform_magnetic_field[] - AssertionError: assert False FAILED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_gauge.py::test_phase_sign - assert False FAILED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/physics/tests/test_noise.py::test_twoterminal - AssertionError: FAILED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/test_mumps.py::test_output - AssertionError: FAILED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/test_mumps.py::test_one_lead - AssertionError: FAILED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/test_mumps.py::test_two_equal_leads - AssertionError: FAILED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/test_mumps.py::test_graph_system - AssertionError: FAILED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/test_mumps.py::test_singular_graph_system - AssertionError: FAILED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/test_mumps.py::test_tricky_singular_hopping - AssertionError: FAILED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/test_mumps.py::test_many_leads - AssertionError: FAILED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/test_mumps.py::test_selfenergy - AssertionError: FAILED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/test_mumps.py::test_selfenergy_reflection - AssertionError: FAILED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/solvers/tests/test_mumps.py::test_ldos - AssertionError: FAILED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_builder.py::test_ModesLead_and_SelfEnergyLead - AssertionError: FAILED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_comprehensive.py::test_qhe - assert 52.26315327726159 < 1e-07 FAILED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_operator.py::test_opservables_scattering - assert False FAILED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_operator.py::test_opservables_spin - assert False FAILED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_operator.py::test_opservables_gauged - assert False FAILED miniconda3/envs/myKwant/lib/python3.11/site-packages/kwant/tests/test_plotter.py::test_current_interpolation - assert 0.9857290648385542 < -0.7 ================= 22 failed, 335 passed, 7 skipped, 4 warnings in 24.20s ================= >>>