Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ dev = [
"pre-commit>=4.2.0",
"ruff>=0.11.4",
"pytest>=7.0",
"pytest-profiling",
"flameprof",
]

[tool.pytest.ini_options]
testpaths = ["tests"]
python_files = "test_*.py"
addopts = "-v"
addopts = "-v -m 'not profiling'"
3 changes: 2 additions & 1 deletion src/dementpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,5 @@ def main():
os.chdir('../'+output_folder)
export(Output_init, site, outname)

main()
if __name__ == '__main__':
main()
6 changes: 3 additions & 3 deletions src/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,8 @@ def metabolism(self,day):
# Update Substrates pools with dead enzymes
DeadEnz_df = pd.concat(
[Enzyme_Loss,
Enzyme_Loss.mul(self.Enz_Attrib['N_cost'].tolist()*self.gridsize,axis=0),
Enzyme_Loss.mul(self.Enz_Attrib['P_cost'].tolist()*self.gridsize,axis=0)],
Enzyme_Loss.mul(np.repeat(self.Enz_Attrib['N_cost'].values, self.gridsize), axis=0),
Copy link
Contributor Author

@Mikolaj-A-Kowalski Mikolaj-A-Kowalski Jun 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 'float64' was appearing here.

tolist method would return a list of Python's floats, which are double precision.

Enzyme_Loss.mul(np.repeat(self.Enz_Attrib['P_cost'].values, self.gridsize), axis=0)],
axis=1
)
DeadEnz_df.index = [np.arange(self.gridsize).repeat(self.n_enzymes), DeadEnz_df.index] # create a multi-index
Expand Down Expand Up @@ -713,5 +713,5 @@ def reinitialization(self,initialization,microbes_pp,output,mode,pulse,*args):
# last: assign microbes to each grid box randomly based on prior densities
choose_taxa = np.zeros((self.n_taxa,self.gridsize), dtype='int8')
for i in range(self.n_taxa):
choose_taxa[i,:] = np.random.choice([1,0], self.gridsize, replace=True, p=[frequencies[i], 1-frequencies[i]])
choose_taxa[i,:] = np.random.binomial(1, frequencies[i], self.gridsize)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I changed the numbers back to "float32" this sampling started failing saying that the probabilities do not sum to 1.0. I presume they must be converted to "float64" before getting summed inside np.random.random_choice.

I have changed the sampling to binominal, which i believe should be equivalent and would avoid the summation errors.

self.Microbes.loc[np.ravel(choose_taxa,order='F')==0] = np.float32(0) # NOTE order='F'
18 changes: 18 additions & 0 deletions tests/profiling/test_profiling.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""Test(s) to use with pytest-profiling to identify bottlenecks in the code."""
import pytest

@pytest.mark.profiling
def test_profiling(monkeypatch):

# Define the command line arguments
import sys
argv = ['dementpy.py', 'grassland', 'output', '20250402', 'scrubland']
monkeypatch.setattr(sys, 'argv', argv)

# Move to subfolder so input and output folders will be correct
import os
os.chdir('src')

# Run dementpy
import dementpy
dementpy.main()
File renamed without changes.
File renamed without changes.
File renamed without changes.