Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/tests #1191

Merged
merged 70 commits into from
Apr 29, 2022
Merged

Refactor/tests #1191

merged 70 commits into from
Apr 29, 2022

Conversation

akaviaLab
Copy link
Contributor

@akaviaLab akaviaLab commented Mar 23, 2022

Looks like this broke the test suite. Odd. Tox worked on my computer.

@codecov-commenter
Copy link

codecov-commenter commented Mar 23, 2022

Codecov Report

Merging #1191 (969f4ea) into devel (b628572) will decrease coverage by 0.74%.
The diff coverage is 85.71%.

❗ Current head 969f4ea differs from pull request most recent head e13e8df. Consider uploading reports for the commit e13e8df to get more accurate results

@@            Coverage Diff             @@
##            devel    #1191      +/-   ##
==========================================
- Coverage   84.40%   83.66%   -0.75%     
==========================================
  Files          65       66       +1     
  Lines        5497     5511      +14     
  Branches     1263     1265       +2     
==========================================
- Hits         4640     4611      -29     
- Misses        557      598      +41     
- Partials      300      302       +2     
Impacted Files Coverage Δ
src/cobra/core/dictlist.py 89.82% <ø> (ø)
src/cobra/core/metabolite.py 65.95% <ø> (ø)
src/cobra/core/model.py 87.80% <ø> (ø)
src/cobra/core/reaction.py 86.89% <ø> (ø)
src/cobra/flux_analysis/gapfilling.py 92.70% <ø> (ø)
src/cobra/flux_analysis/phenotype_phase_plane.py 83.00% <ø> (ø)
src/cobra/io/json.py 68.75% <60.00%> (+1.00%) ⬆️
src/cobra/io/yaml.py 56.41% <75.00%> (+1.14%) ⬆️
src/cobra/io/web/cobrapy_repository.py 100.00% <100.00%> (ø)
src/cobra/io/web/load.py 84.78% <100.00%> (+1.06%) ⬆️
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b628572...e13e8df. Read the comment docs.

@synchon
Copy link
Member

synchon commented Mar 24, 2022

I believe what @Midnighter meant in #974 was to move src/cobra/test/ to tests/ (or, test/). Personally, I would not do this until we have completed the codebase modernization and flake8 is running in CI/CD. As this move will migrate data files and the tests, this will also need to take care of cobra.test.create_test_model(). Maybe others can also add their opinion about the move.

@akaviaLab
Copy link
Contributor Author

Okay.
I can move it from src/tests to tests.

However, that will cause a bit of a problem since importing/using this in cobra without the source directory (as it is installed by a package) would be difficult. Two options for this are

  1. Put the function create_model in src/scripts so it is installed locally
  2. Put the function create_model in cobra.util directory (for example) and have it imported into tests. Tests can import from cobra, but removing init.py means that cobra has a hard time importing from tests.

I can use Docker to check it to make sure it is present and workable, including data, but I'd like a decision from the other devs on location please, if that's possible.

@Midnighter
Copy link
Member

Indeed, my goal there was to have a /tests directory next to the /src/cobra directory. And I think it's actually a feature that the test suite is not installed with the source package.

The load_model function should be the replacement for create_test_model in documentation and examples everywhere. I think changing examples is the real major piece of work and the reason I didn't proceed on this so far. Within the test suite itself, we should have a few pytest fixtures that provide models.

@akaviaLab
Copy link
Contributor Author

I think I see.
Would you like the cobra package to have some example data, so people can load_model even if there is no internet? Currently, create_test_model() has the advantage that it can work when no internet is available.

@Midnighter
Copy link
Member

Would you like the cobra package to have some example data, so people can load_model even if there is no internet? Currently, create_test_model() has the advantage that it can work when no internet is available.

It's a valid concern. I'm not against packaging some models, also so that users have the exact models that examples were run with. Please note that in normal use load_model will cache the download locally so after first load, a connection will not be necessary. And you do need a connection to install cobrapy, of course.

@akaviaLab
Copy link
Contributor Author

Is there any way to setup the package so that some example models are already loaded in the cache? I don't think so, and it might not be a good idea.
However, if it is possible and a reasonable idea, one or two models can start cached.

Alternatively, a possible (but not great) idea is to add some edge cases to load_model, so if it gets "textbook", which isn't in any of the repositories, it will load it locally from cobra data.

I'm just trying to think of users that are very new to cobrapy, and want to load some models to see behavior.

@Midnighter
Copy link
Member

Is there any way to setup the package so that some example models are already loaded in the cache? I don't think so, and it might not be a good idea.
However, if it is possible and a reasonable idea, one or two models can start cached.

It can be done as a post-installation step but it's a bad idea, I think, because it assumes that the cache directory can be written to (this is not always the case).

Adding a utility function and distributing the models with the package is the best option, IMO. The only question is then if they should be in SBML or pickle format.

@cdiener
Copy link
Member

cdiener commented Mar 29, 2022

I think we could get rid of the pickle ones because those are a pain to maintain anyways. I think having some manually validated JSON and YAML ones would be good though to reproduce bugs etc. I agree with using load_model just have to make sure it's a new release (not backwards compatible). The test models could act like a new provider "local" or "cobrapy" similar to the bio models one.

@akaviaLab
Copy link
Contributor Author

Are the mini models validated?
I was thinking about getting update_pickles.py to copy some files to src/data. Set update_pickles.py to run before release.
Then the source version is still in tests/data, and that gets modified.

Or I could copy the mini models manually to src/data, and those would be examples.

So, load_models should have a repository like BiggModels which will be cobrapy, and that will use import_resources to import files. I think import_resources makes sure that however the users install the package, the data files are available.

@akaviaLab
Copy link
Contributor Author

I fixed all the usages of create_test_model in the code examples.

I'd be happy to fix the python notebooks, but can you please tell me what needs to happen?
Do I just need to replace create_test_model with the appropriate call (simple text replacing like the examples)
OR do I need to manually run the Jupyter notebooks

Thank you

@Midnighter
Copy link
Member

Dear @akaviaLab,

I would love to get this one and your other works merged. I tried to send you an email in order to set up a call to discuss this and the compartments PR but it came back with access denied. Can you please write to me or head over to https://gitter.im/opencobra/cobrapy where we can talk a bit more disconnected from code.

@synchon
Copy link
Member

synchon commented Apr 26, 2022

I think changing examples is the real major piece of work and the reason I didn't proceed on this so far.

@Midnighter Can we maybe take this opportunity to have our how-to Jupyter notebooks hosted on Binder ? I believe this will let new users to play around easily with cobrapy without hitting Python and related hurdles (we have seen quite a few 😅).

I think having some manually validated JSON and YAML ones would be good though to reproduce bugs etc.

@cdiener Would that be a good reason to have a separate repository for them or do we continue with as it is now?

@Midnighter
Copy link
Member

@Midnighter Can we maybe take this opportunity to have our how-to Jupyter notebooks hosted on Binder ? I believe this will let new users to play around easily with cobrapy without hitting Python and related hurdles (we have seen quite a few sweat_smile).

Yes, can't remember where but Binder was mentioned and approved before by everyone involved. Just™️ need to do it 😉

@synchon
Copy link
Member

synchon commented Apr 26, 2022

Yes, can't remember where but Binder was mentioned and approved before by everyone involved. Just™️ need to do it 😉

Okay then I can take a stab at it in a few days 😁

@akaviaLab
Copy link
Contributor Author

@Midnighter Posted on gitter
@synchon can you wait a bit before starting to work on binder? I"m working on this refactoring and discussing it with @Midnighter. Thank you

@akaviaLab
Copy link
Contributor Author

All the notebook files done, except for faq.ipynb, which had functions I couldn't figure out.

@synchon
Copy link
Member

synchon commented Apr 26, 2022

@synchon can you wait a bit before starting to work on binder? I"m working on this refactoring and discussing it with @Midnighter. Thank you

Yes of course. I would have waited anyway to get this PR merged. 😄

@akaviaLab
Copy link
Contributor Author

@synchon Great!
If you can review faq.ipynb, I'd appreciate it.

"import cobra.test\n",
"model = cobra.test.create_test_model()\n",
"import cobra.io\n",
"model = cobra.io.load_model(\"iYS1720\")\n",
"\n",
"for metabolite in model.metabolites:\n",
" metabolite.id = \"test_\" + metabolite.id\n",
Copy link
Member

Choose a reason for hiding this comment

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

Would be nice to use f-string here to keep up with modern Python.

@synchon
Copy link
Member

synchon commented Apr 28, 2022

@akaviaLab faq.ipynb looks okay after your changes.

One comment about the section How do I generate an LP file from a COBRA model?: The solvers are now optlang-based and internal cobrapy solvers don't exist anymore, so better to remove the unnecessary sub-section. While you are at it, maybe also rename COBRA to cobrapy just to be consistent.

Also, this line With optlang solvers, the LP formulation of a model is obtained by it's string representation. All solvers behave the same way. has a small typo: ... obtained by its string .... Would be nice if you can fix that as well.

Any other enhancements, can be tackled later in a different PR later.

@akaviaLab
Copy link
Contributor Author

Fixed comments. Set it up to be based on the most recent version of #1208 so it can be merged afterwards. If anything else is merged before this is done. I will rebase it.

Copy link
Member

@synchon synchon left a comment

Choose a reason for hiding this comment

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

Looks good. Thanks for the effort!

documentation_builder/deletions.ipynb Outdated Show resolved Hide resolved
documentation_builder/deletions.ipynb Outdated Show resolved Hide resolved
documentation_builder/deletions.ipynb Outdated Show resolved Hide resolved
documentation_builder/constraints_objectives.ipynb Outdated Show resolved Hide resolved
documentation_builder/faq.ipynb Outdated Show resolved Hide resolved
src/cobra/manipulation/delete.py Outdated Show resolved Hide resolved
tests/test_io/test_pickle.py Outdated Show resolved Hide resolved
benchmarks/cobra-cameo-merge-benchmarks-before-merge.ipynb Outdated Show resolved Hide resolved
benchmarks/cobra-cameo-merge-benchmarks.ipynb Show resolved Hide resolved
Copy link
Contributor Author

@akaviaLab akaviaLab left a comment

Choose a reason for hiding this comment

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

Fixed your comments. When the review is done, I will merge the changes to the mat file and resolve conflict - not doing it now, since it will break conversations.

benchmarks/cobra-cameo-merge-benchmarks.ipynb Show resolved Hide resolved
src/cobra/manipulation/delete.py Outdated Show resolved Hide resolved
tests/test_io/test_json.py Outdated Show resolved Hide resolved
@Midnighter
Copy link
Member

@Midnighter - would you like me to squash the commits of the notebooks? I had one commit for each notebook code and one commit for each notebook output. I can squash them to one commit per notebook if that will help.

No, that actually sounds good to me.

@Midnighter
Copy link
Member

I see now that you moved things to /src/tests rather than /tests. Would it have a huge impact on the other commits if you changed that now?

@akaviaLab
Copy link
Contributor Author

akaviaLab commented Apr 29, 2022 via email

Copy link
Member

@Midnighter Midnighter left a comment

Choose a reason for hiding this comment

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

Phew, thank you so much for tackling this 🙂 I have a few more suggestions but overall it looks very good.

One bigger point is the exact models that we want to distribute with COBRApy. Seems like only the SBML files are needed there but maybe I overlooked something.

We should also look at including jupytext because those notebooks diffs are just painful. That's not for this PR, though.

@@ -79,8 +79,8 @@ where = src

[options.package_data]
cobra =
io/*.json
test/data/*
data/*
Copy link
Member

Choose a reason for hiding this comment

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

I would like to reduce the models that we distribute with the package. Most of those are only really useful for testing and should be part of the repository but not the distributed Python package, I think.

Copy link
Member

Choose a reason for hiding this comment

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

Essentially, keep all SBML models for the examples and the others should be moved into a tests/data directory or so.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm. I kept yaml, json, pickle and mat in the mini model format, just so we can show what they're supposed to look like.
I can definitely delete iJO1366.pickle.
As for the mini models - I'll agree to what you want.

Copy link
Member

Choose a reason for hiding this comment

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

Fair enough, they hardly hurt. Then just remove the pickle file, please.

src/cobra/io/web/cobrapy_repository.py Outdated Show resolved Hide resolved
release-notes/next-release.md Outdated Show resolved Hide resolved
src/cobra/io/web/load.py Outdated Show resolved Hide resolved
tests/conftest.py Outdated Show resolved Hide resolved
tests/test_io/test_pickle.py Outdated Show resolved Hide resolved
tests/test_io/test_pickle.py Outdated Show resolved Hide resolved
tests/test_io/test_yaml.py Outdated Show resolved Hide resolved
tests/test_io/test_yaml.py Outdated Show resolved Hide resolved
tests/test_io/test_yaml.py Outdated Show resolved Hide resolved
akaviaLab and others added 3 commits April 29, 2022 09:24
Co-authored-by: Moritz E. Beber <midnighter@posteo.net>
using tmp_path instead of py.test (need to remove os.join in later PR)
@Midnighter
Copy link
Member

Looks good to me now. As soon as @synchon is happy, we can merge it. Cheers @akaviaLab

@akaviaLab
Copy link
Contributor Author

akaviaLab commented Apr 29, 2022 via email

Copy link
Member

@synchon synchon left a comment

Choose a reason for hiding this comment

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

Perfect! Let's merge this. 🎉

@synchon
Copy link
Member

synchon commented Apr 29, 2022

@Midnighter can we make a release after merging this PR?

@Midnighter
Copy link
Member

@Midnighter can we make a release after merging this PR?

Sure

Might need to remove test_all

Yep, please do.

@Midnighter Midnighter merged commit 91dfcfc into opencobra:devel Apr 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move the test suite out of the source tree
5 participants