broadinstitute / CellBender

CellBender is a software package for eliminating technical artifacts from high-throughput single-cell RNA sequencing (scRNA-seq) data.
https://cellbender.rtfd.io
BSD 3-Clause "New" or "Revised" License
285 stars 52 forks source link

Fix exception loading checkpoint #345

Closed alecw closed 5 months ago

alecw commented 6 months ago

Addresses the following exception that occurs when re-running with a machine with more memory:

cellbender:remove-background: Running inference...
Traceback (most recent call last):
  File "/opt/conda/bin/cellbender", line 8, in <module>
    sys.exit(main())
  File "/opt/conda/lib/python3.7/site-packages/cellbender/base_cli.py", line 123, in main
    cli_dict[args.tool].run(args)
  File "/opt/conda/lib/python3.7/site-packages/cellbender/remove_background/cli.py", line 185, in run
    return main(args)
  File "/opt/conda/lib/python3.7/site-packages/cellbender/remove_background/cli.py", line 219, in main
    posterior = run_remove_background(args)
  File "/opt/conda/lib/python3.7/site-packages/cellbender/remove_background/run.py", line 113, in run_remove_background
    inferred_model, _, _, _ = run_inference(dataset_obj=dataset_obj, args=args)
  File "/opt/conda/lib/python3.7/site-packages/cellbender/remove_background/run.py", line 768, in run_inference
    final_elbo_fail_fraction=args.final_elbo_fail_fraction)
  File "/opt/conda/lib/python3.7/contextlib.py", line 74, in inner
    return func(*args, **kwds)
  File "/opt/conda/lib/python3.7/site-packages/cellbender/remove_background/train.py", line 248, in run_training
    best_test_elbo = max(test_elbo)
ValueError: max() arg is an empty sequence

Note that I don't understand the checkpoint code very well, so there may be a cleaner way to do this. I simply eliminated the test_elbo local variable and refer to the list stored in the model directly.

Also, html generation was failing because the way lxml.html.clean needs to be installed has changed, so DockerfileGit contains a fix for that.

sjfleming commented 5 months ago

This seems like a reasonable fix to me, thanks!

I'm including the lxml_html_clean package as a dependency in requirements.txt in #347 , so I think I would just want your first commit, but not this one: https://github.com/broadinstitute/CellBender/pull/345/commits/09646e6ec59f13842cbf700b8a3f10896afd3010

alecw commented 5 months ago

OK, I just removed the lxml_html_clean commit.

sjfleming commented 5 months ago

Looks good to me, thank you @alecw !