mooreryan / divnet-rs

A fast implementation of DivNet
https://mooreryan.github.io/divnet-rs-book/
Apache License 2.0
3 stars 0 forks source link

cargo test fails with matrix::tests::eignen_gets_eigenvalues_and_vectors #6

Open cramjaco opened 2 years ago

cramjaco commented 2 years ago

I've installed divnet-rs, and it seems to run as expected (eg divnet-rs ./test_files/small/config_small.toml works). However, if I run cargo test I get the error message:


> failures:
> 
> ---- matrix::tests::eigen_gets_eigenvalues_and_vectors stdout ----
> thread 'matrix::tests::eigen_gets_eigenvalues_and_vectors' panicked at 'assertion failed: actual.vectors.approx_eq(&expected.vectors, TOL) ||\n    actual.vectors.approx_eq(&opposite_expected_values.vectors, TOL)', src/matrix/mod.rs:1684:9
> 
> 
> failures:
>     matrix::tests::eigen_gets_eigenvalues_and_vectors
> 
> test result: FAILED. 52 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.19s
> 
> error: test failed, to rerun pass '--lib'

Can I ignore this, or should I be doing something else.

I installed rust and openblas in a condas enviornment for what its worth. Also I'm using release version of divnet divnet-rs-0.2.1

Thanks for your consideration.

mooreryan commented 2 years ago

Hey, thanks for the bug report. Do you feel comfortable with adding a few lines to one of the rust files to add some debug output? (I ask because I don't want to assume too much or too little about your coding experience.) If so, then I can show you how to add some debug statements and we can see if the problem is severe. That's probably the simplest way to answer this question.

The longer answer is that the floating point comparisons used in the tests are a bit hacky and need to be made a little more robust. But it is likely that it is failing because at least one of the values is outside the tolerance allowed by the test.

cramjaco commented 2 years ago

I'm happy to give it a try! I'm currently running divnet-rs on my actual data and it seems to be working, which is awesome. I plan to hold off on changing anything until after my job finishes but if you give me instructions, I'll try to follow them sometime next week probably.

benyoung93 commented 2 years ago

Hi hi

Just thought I would pop this in as I have recently upgraded to a M1 mac chip. Tested the conda and got the same error, however using brew for GCC and openblas installation everything is a-okay. For anyone else looking I would recommend using good old brew for installation.

Compiling divnet-rs v0.2.1 (/Users/benjamin.d.young/programs/divnet-rs-0.2.1)
   Finished test [unoptimized + debuginfo] target(s) in 1.10s
     Running unittests src/lib.rs (target/debug/deps/divnet_rs-9d443afa3bef53c2)

running 53 tests
test conversions::tests::to_log_ratios_works ... ok
test conversions::tests::output_matches_r::to_composition_matrix_matches_r ... ok
test conversions::tests::output_matches_r::you_get_the_correct_compositions_from_counts ... ok
test conversions::tests::to_log_ratios_handles_zero_counts_in_base_taxa ... ok
test conversions::tests::output_matches_r::to_log_ratios_matches_r ... ok
test conversions::tests::to_log_ratios_handles_zero_counts_in_non_base_taxa ... ok
test fit_aitchison::tests::diagonal_network_makes_diagonal_networks ... ok
test fit_aitchison::tests::remove_at_returns_a_vec_without_idx ... ok
test fit_aitchison::tests::streaming_mean_works ... ok
test fit_aitchison::tests::streaming_mean_panics_on_empty_array - should panic ... ok
test matrix::ewise::tests::map_maps_a_fn_onto_a_vec ... ok
test matrix::ewise::tests::sum_sums_elements ... ok
test matrix::ewise::tests::test_add ... ok
test matrix::ewise::tests::test_div ... ok
test matrix::ewise::tests::test_ln ... ok
test matrix::ewise::tests::test_mul ... ok
test matrix::ewise::tests::test_sub ... ok
test matrix::ewise::tests::zipmap_maps_a_fn_onto_two_vecs_lockstep ... ok
test matrix::ewise::tests::zipmap_panics_if_vecs_are_different_lengths - should panic ... ok
test matrix::tests::center_centers_cols_by_mean ... ok
test matrix::tests::center_centers_rows_by_mean ... ok
test matrix::tests::col_returns_a_column_slice ... ok
test matrix::tests::col_sums_sums_colss ... ok
test matrix::tests::colmeans_gets_column_means ... ok
test matrix::tests::covariance_gets_cov_matrix ... ok
test matrix::tests::covariance_gets_covariance_of_two_slices ... ok
test matrix::tests::diag_gets_elements_on_the_diagonal ... ok
test matrix::tests::element_wise_ops1::exp_does_element_wise_exp ... ok
test matrix::tests::element_wise_ops1::ln_does_element_wise_natural_log ... ok
test matrix::tests::element_wise_ops2::eadd_does_elementwise_addition ... ok
test matrix::tests::element_wise_ops2::ediv_does_elementwise_division ... ok
test matrix::tests::element_wise_ops2::emul_does_elementwise_multiplication ... ok
test matrix::tests::element_wise_ops2::esub_does_elementwise_subtraction ... ok
test matrix::tests::equality::approx_eq_checks_equality_within_tolerance ... ok
test matrix::tests::equality::eq_checks_equality ... ok
test matrix::tests::get_gets_elements ... ok
test matrix::tests::get_unchecked_gets_elements_without_bounds_checking ... ok
test matrix::tests::multiple_cols_returns_mutliple_columns ... ok
test matrix::tests::mmul2_multiplies_two_matrices ... ok
test matrix::tests::row_gets_a_single_row_from_array ... ok
test matrix::tests::row_sums_sums_rows ... ok
test matrix::tests::set_sets_elements ... ok
test matrix::tests::set_unchecked_sets_elements_without_bounds_checking ... ok
test matrix::tests::summary::sum_sums_all_elems ... ok
test matrix::tests::to_diag_makes_a_vec_into_diagonal_array ... ok
test matrix::tests::solve ... ok
test matrix::tests::transpose_transposes_a_matrix ... ok
test matrix::tests::variance_gets_variance_of_slice ... ok
test matrix::tests::eigen_gets_eigenvalues_and_vectors ... ok
test mvrnorm::tests::mvrnorm_gives_correct_mu_and_sigma ... ok
test fit_aitchison::tests::fit_aitchison_gives_reasonable_result ... ok
test fit_aitchison::tests::fit_aitchison_gives_reasonable_result2 ... ok
test multinomial::tests::test_multinomial ... ok

test result: ok. 53 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.13s
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
mooreryan commented 2 years ago

Thanks @benyoung93 for posting!

Just so I'm clear...on your M1 mac, when you used homebrew to install gcc and openblas everything was working fine, but when using conda to install gcc and openblas, it was not working? If that is the case, I should put a note in the installation instructions in the manual!

It is good to hear that you could get it working on an M1 mac...I do not have one to test it out on.

benyoung93 commented 2 years ago

Hi @mooreryan Of course, let me provide some more info.

So Conda installs I was running into a number of problems, so much so that I just gave up and moved to brew. Brew was very simple. I do not know if this is new to the M1, or if this is the root install for homebrew, but the LIBRARY_PATH and LD_LIBRARY_PATH that i have in my .zshrc are as follows.

LIBRARY_PATH="/opt/homebrew/opt/openblas/lib"
LIBRARY_PATH="${LIBRARY_PATH}:/opt/homebrew/Cellar/gcc/11.3.0_1/lib/gcc/11"
LIBRARY_PATH="${LIBRARY_PATH}:/opt/homebrew/bin"
LIBRARY_PATH="${LIBRARY_PATH}:/usr/bin"
LD_LIBRARY_PATH="/opt/homebrew/opt/openblas/lib"
LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/opt/homebrew/Cellar/gcc/11.3.0_1/lib/gcc/11"
LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/opt/homebrew/bin"
LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/bin"
export LIBRARY_PATH
export LD_LIBRARY_PATH

As you can see I have some additional variables in these, I need to double check whether they are all needed (i.e. me trying to locate exactly what to have here took a hot second).

If this is all done then build works fine and the cargo test also works with no errors.

Another thing, when brewing openblas you get this message

openblas is keg-only, which means it was not symlinked into /opt/homebrew,
because macOS provides BLAS in Accelerate.framework.

For compilers to find openblas you may need to set:
  export LDFLAGS="-L/opt/homebrew/opt/openblas/lib"
  export CPPFLAGS="-I/opt/homebrew/opt/openblas/include"

==> Summary

🍺  /opt/homebrew/Cellar/openblas/0.3.20: 23 files, 56.1MB

As you can see I included the homebrew in the LIBRARY and LD_LIBRARY paths and it worked fine and not those suggested export flags :).

If you want anything else tested with the M1 please let me know. I can tell you now 6k ASVs and 200 samples ran in about a minute 😂.