Example fails bc mut_prob is not found in params.py
jenzopr opened this issue · comments
Hi! I tried to follow the example provided in the README and as well in the docs at readthedocs.
However, the examples (python -m casim.casim 1
) fail with
Traceback (most recent call last):
File "/home/jpreuss/.conda/envs/casim/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/home/jpreuss/.conda/envs/casim/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/jpreuss/cancer_sim/casim/casim.py", line 1112, in <module>
sys.exit(main(arguments))
File "/home/jpreuss/cancer_sim/casim/casim.py", line 1021, in main
mutation_probability = params.mut_prob,
AttributeError: module 'params' has no attribute 'mut_prob'
I had to change mutation_probabilty
in line 20 of params.py to mut_prob
.
Both, the REAMDE and the docs at readthedocs contain the path to test/params.py
as params file. The source distribution does not contain the file at this location (rather at casim/params.py
). Maybe update the docs and as an additional suggestion, I could imagine that a params
parameter to casim.casim
would help to point the software to the parameter file that should be used (instead of relying on the presence of a file called params.py
).
Best,
Jens
This issue is part of the JOSS review at openjournals/joss-reviews#2436
I got the same error when I tried to run the examples from within the cancer_sim directory.
However, when I switched to a different directory and ran them they seemed to work ok. Maybe this a problem too? I'm not sure at the moment where the main function is reading the params from in this case.
As suggested by @jenzopr, I think having a required params
flag for casim.casim
is probably the better way to point it to the params file/module. With this approach, you could also give users a little more flexibility in naming their parameter modules, as opposed to just having them named params.py
.
I'll also note that from the current documentation it wasn't entirely clear to me at first that casim.casim by default imports parameters from the param.py, and that it tries to find it in the current working directory. I think you may need to make this more explicit in the documentation. However, this comment would probably be moot if you implement the params
flag/parmameter for casim.casim
calls.
i fixed the original issue in PR #14 but i'll also refactor the handling of params.py
taking into account the suggestions above.
Done (54b8868)
I cloned and reinstalled casim using git
and python setup.py install
, which bumps casim to 1.0.0
. However ./run_tests.sh
still fails with 10 errors..
test_check_set_number (__main__.CancerSimulatorParametersTest)
Test the numer checking utility. ... ok
test_default_constructor (__main__.CancerSimulatorParametersTest)
Test initialization without arguments. ... ERROR
test_shaped_constructor (__main__.CancerSimulatorParametersTest)
Test initialization with arguments. ... ERROR
test_default_constructor (__main__.CancerSimulatorTest)
Test the construction of the Simulator without arguments. ... ok
test_export_tumour_matrix (__main__.CancerSimulatorTest)
Test exporting the tumour matrix. ... /home/jpreuss/.conda/envs/casim/lib/python3.7/site-packages/numpy/matrixlib/defmatrix.py:71: PendingDeprecationWarning: the matrix subclass is not the recommended way to represent matrices or deal with linear algebra (see https://docs.scipy.org/doc/numpy/user/numpy-for-matlab-users.html). Please adjust your code to use regular ndarray.
return matrix(data, dtype=dtype, copy=False)
ok
test_high_sampling_fraction (__main__.CancerSimulatorTest)
Test run with sampling_fraction=0.9 ... ERROR
test_init_step_increases (__main__.CancerSimulatorTest)
Check the the internal step counter is propely updated. ... ERROR
test_params_module (__main__.CancerSimulatorTest)
Check that starting a run with params.py paramters sets all ... 2020-09-03 14:42:24,155 INFO: Running in single tumour mode.
2020-09-03 14:42:24,155 INFO: First cell at (5, 5).
2020-09-03 14:42:24,155 INFO: Tumour growth in progress.
/home/jpreuss/.conda/envs/casim/lib/python3.7/site-packages/numpy/matrixlib/defmatrix.py:71: PendingDeprecationWarning: the matrix subclass is not the recommended way to represent matrices or deal with linear algebra (see https://docs.scipy.org/doc/numpy/user/numpy-for-matlab-users.html). Please adjust your code to use regular ndarray.
return matrix(data, dtype=dtype, copy=False)
2020-09-03 14:42:24,157 INFO: All generations finished. Starting tumour reconstruction.
2020-09-03 14:42:24,157 INFO: Reconstruction done, get statistics.
2020-09-03 14:42:24,157 INFO: Exporting simulation data
2020-09-03 14:42:24,272 INFO: Growth curve graph written to cancer_sim_out/cancer_1/simOutput/growthCurve.pdf.
2020-09-03 14:42:24,299 INFO: Consumed Wall time of this run: 0.143774 s.
ERROR
test_reference_data_1mut (__main__.CancerSimulatorTest)
Run a reference test and compare against reference data. ... ERROR
test_reference_data_50mut (__main__.CancerSimulatorTest)
Run a reference test and compare against reference data. ... ERROR
test_sampling_output (__main__.CancerSimulatorTest)
Check that output generated by the sampling postprocessing goes to the correct path. ... ERROR
test_sampling_positions (__main__.CancerSimulatorTest)
Check setting the sample positions generates the expected output. ... ERROR
test_serialize (__main__.CancerSimulatorTest)
The the serialization of the entire object. ... ERROR
test_setup_io (__main__.CancerSimulatorTest)
Test the IO handling. ... ok
test_10x10_seed_1 (__main__.casim_test)
Run a test case with 10x10 cells and prng seed 1. ... 2020-09-03 14:42:24,499 INFO: Running in single tumour mode.
2020-09-03 14:42:24,499 INFO: First cell at (5, 5).
2020-09-03 14:42:24,499 INFO: Tumour growth in progress.
/home/jpreuss/.conda/envs/casim/lib/python3.7/site-packages/numpy/matrixlib/defmatrix.py:71: PendingDeprecationWarning: the matrix subclass is not the recommended way to represent matrices or deal with linear algebra (see https://docs.scipy.org/doc/numpy/user/numpy-for-matlab-users.html). Please adjust your code to use regular ndarray.
return matrix(data, dtype=dtype, copy=False)
2020-09-03 14:42:24,499 DEBUG: Cell matrix:
[[0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 1 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0]]
2020-09-03 14:42:24,500 DEBUG: 0/2 generation started
2020-09-03 14:42:24,500 DEBUG: list of cancer cells [(5, 5)]
2020-09-03 14:42:24,500 DEBUG: cell to divide (5, 5)
2020-09-03 14:42:24,500 DEBUG: index of the mother cell: 1
2020-09-03 14:42:24,500 DEBUG: random neighbor to divide: (5, 6)
2020-09-03 14:42:24,500 DEBUG: Neighbor cell has new index 2
2020-09-03 14:42:24,500 DEBUG: 1, 2
2020-09-03 14:42:24,500 DEBUG: mut container updated: [(0, 0), (0, 1), (1, 2)]
2020-09-03 14:42:24,501 DEBUG: Cell matrix:
[[0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 3 2 0 0 0]
[0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0]]
2020-09-03 14:42:24,501 DEBUG: 1/2 generation started
2020-09-03 14:42:24,501 DEBUG: list of cancer cells [(5, 5), (5, 6)]
2020-09-03 14:42:24,501 DEBUG: cell to divide (5, 5)
2020-09-03 14:42:24,501 DEBUG: index of the mother cell: 3
2020-09-03 14:42:24,501 DEBUG: random neighbor to divide: (6, 5)
2020-09-03 14:42:24,501 DEBUG: Neighbor cell has new index 4
2020-09-03 14:42:24,501 DEBUG: 3, 4
2020-09-03 14:42:24,501 DEBUG: mut container updated: [(0, 0), (0, 1), (1, 2), (1, 3), (3, 4)]
2020-09-03 14:42:24,501 DEBUG: cell to divide (5, 6)
2020-09-03 14:42:24,502 DEBUG: index of the mother cell: 2
2020-09-03 14:42:24,502 DEBUG: random neighbor to divide: (4, 6)
2020-09-03 14:42:24,502 DEBUG: Neighbor cell has new index 6
2020-09-03 14:42:24,502 DEBUG: 2, 6
2020-09-03 14:42:24,502 DEBUG: mut container updated: [(0, 0), (0, 1), (1, 2), (1, 3), (3, 4), (3, 5), (2, 6)]
2020-09-03 14:42:24,502 INFO: All generations finished. Starting tumour reconstruction.
2020-09-03 14:42:24,502 DEBUG: Untangling cell 5.
2020-09-03 14:42:24,502 DEBUG: Untangling cell 7.
2020-09-03 14:42:24,502 DEBUG: Untangling cell 4.
2020-09-03 14:42:24,502 DEBUG: Untangling cell 6.
2020-09-03 14:42:24,502 INFO: Reconstruction done, get statistics.
2020-09-03 14:42:24,502 INFO: Exporting simulation data
2020-09-03 14:42:24,613 INFO: Growth curve graph written to cancer_sim_out/cancer_1/simOutput/growthCurve.pdf.
2020-09-03 14:42:24,638 DEBUG: Untangling cell 5.
2020-09-03 14:42:24,639 INFO: Consumed Wall time of this run: 0.139721 s.
ok
test_cli (__main__.casim_test)
Test the command line interface. ... usage: casim.py [-h] [-o DIR] [--verbose] seed
casim.py: error: the following arguments are required: seed
FAIL
======================================================================
ERROR: test_default_constructor (__main__.CancerSimulatorParametersTest)
Test initialization without arguments.
----------------------------------------------------------------------
Traceback (most recent call last):
File "casim_test.py", line 57, in test_default_constructor
self.assertEqual(parameters.adv_mutant_division_probability, 1)
AttributeError: 'CancerSimulatorParameters' object has no attribute 'adv_mutant_division_probability'
======================================================================
ERROR: test_shaped_constructor (__main__.CancerSimulatorParametersTest)
Test initialization with arguments.
----------------------------------------------------------------------
Traceback (most recent call last):
File "casim_test.py", line 92, in test_shaped_constructor
plot_tumour_growth=False,
TypeError: __init__() got an unexpected keyword argument 'adv_mutant_division_probability'
======================================================================
ERROR: test_high_sampling_fraction (__main__.CancerSimulatorTest)
Test run with sampling_fraction=0.9
----------------------------------------------------------------------
Traceback (most recent call last):
File "casim_test.py", line 293, in test_high_sampling_fraction
sampling_fraction=0.9,
TypeError: __init__() got an unexpected keyword argument 'adv_mutant_division_probability'
======================================================================
ERROR: test_init_step_increases (__main__.CancerSimulatorTest)
Check the the internal step counter is propely updated.
----------------------------------------------------------------------
Traceback (most recent call last):
File "casim_test.py", line 462, in test_init_step_increases
self.assertEqual(cancer_sim._CancerSimulator__init_step, 0)
AttributeError: 'CancerSimulator' object has no attribute '_CancerSimulator__init_step'
======================================================================
ERROR: test_params_module (__main__.CancerSimulatorTest)
Check that starting a run with params.py paramters sets all
----------------------------------------------------------------------
Traceback (most recent call last):
File "casim_test.py", line 224, in test_params_module
handler.close()
UnboundLocalError: local variable 'handler' referenced before assignment
======================================================================
ERROR: test_reference_data_1mut (__main__.CancerSimulatorTest)
Run a reference test and compare against reference data.
----------------------------------------------------------------------
Traceback (most recent call last):
File "casim_test.py", line 369, in test_reference_data_1mut
sampling_positions=[(501,502)],
TypeError: __init__() got an unexpected keyword argument 'adv_mutant_division_probability'
======================================================================
ERROR: test_reference_data_50mut (__main__.CancerSimulatorTest)
Run a reference test and compare against reference data.
----------------------------------------------------------------------
Traceback (most recent call last):
File "casim_test.py", line 322, in test_reference_data_50mut
sampling_fraction=0.1,
TypeError: __init__() got an unexpected keyword argument 'adv_mutant_division_probability'
======================================================================
ERROR: test_sampling_output (__main__.CancerSimulatorTest)
Check that output generated by the sampling postprocessing goes to the correct path.
----------------------------------------------------------------------
Traceback (most recent call last):
File "casim_test.py", line 498, in test_sampling_output
export_tumour=True,
TypeError: __init__() got an unexpected keyword argument 'adv_mutant_division_probability'
======================================================================
ERROR: test_sampling_positions (__main__.CancerSimulatorTest)
Check setting the sample positions generates the expected output.
----------------------------------------------------------------------
Traceback (most recent call last):
File "casim_test.py", line 539, in test_sampling_positions
export_tumour=True,
TypeError: __init__() got an unexpected keyword argument 'adv_mutant_division_probability'
======================================================================
ERROR: test_serialize (__main__.CancerSimulatorTest)
The the serialization of the entire object.
----------------------------------------------------------------------
Traceback (most recent call last):
File "casim_test.py", line 418, in test_serialize
self.assertEqual(loaded_parameters.adv_mutant_division_probability, parameters.adv_mutant_division_probability)
AttributeError: 'CancerSimulatorParameters' object has no attribute 'adv_mutant_division_probability'
======================================================================
FAIL: test_cli (__main__.casim_test)
Test the command line interface.
----------------------------------------------------------------------
Traceback (most recent call last):
File "casim_test.py", line 592, in test_cli
self.assertEqual(proc.returncode, 0)
AssertionError: 2 != 0
----------------------------------------------------------------------
Ran 16 tests in 1.439s
FAILED (failures=1, errors=10)
Ran casim_test.py in /home/jpreuss/cancer_sim/test.
Log went to /home/jpreuss/cancer_sim/casim_test@2020-09-03T14:42:23.log.
Hi,
I can run the tests properly. Looking at the line numbers of the errors above it is likely that an old version of the package remains. Could you try to remove (manually by going the the site-package directory and rm -r casim*
) and reinstall the package?
Purging the env and reinstalling from scratch worked. Thanks!