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

Remove meta clone everywhere for improved resume stability #332

Merged
merged 9 commits into from
Jul 27, 2023

Conversation

jfy133
Copy link
Member

@jfy133 jfy133 commented Jul 20, 2023

Because of this: https://www.youtube.com/watch?v=A357C-ux6Dw&t=879s

Essentially allows modification of maps without breaking sister maps in other channels.

Further explanation here: https://nfcore.slack.com/archives/C01LNCGJBMH/p1690207154503529?thread_ts=1684849566.995129&cid=C01LNCGJBMH

I've opted for consistency throughput the pipeline as the use of subMap is a bit more powerful as you can make different maps directly in addition to dropping parameters.

(Note that subMap doesn't make a deep copy as it thought it did/posted originally, but using the + - subMap combination is good enough)

I've tested all channels before and after with dumps to make sure they look OK 👍 (i.e., lane merging, fastp, malt, kraken/bracken)

PR checklist

  • This comment contains a description of changes (with reason).
  • If you've fixed a bug or added code that should be tested, add tests!
  • If you've added a new tool - have you followed the pipeline conventions in the contribution docs- [ ] If necessary, also make a PR on the nf-core/taxprofiler branch on the nf-core/test-datasets repository.
  • Make sure your code lints (nf-core lint).
  • Ensure the test suite passes (nextflow run . -profile test,docker --outdir <OUTDIR>).
  • Usage Documentation in docs/usage.md is updated.
  • Output Documentation in docs/output.md is updated.
  • CHANGELOG.md is updated.
  • README.md is updated (including new tool citations and authors/contributors).

@jfy133 jfy133 requested a review from a team July 20, 2023 12:46
@github-actions
Copy link

github-actions bot commented Jul 20, 2023

nf-core lint overall result: Passed ✅ ⚠️

Posted for pipeline commit 91fc6f7

+| ✅ 157 tests passed       |+
!| ❗   1 tests had warnings |!

❗ Test warnings:

  • pipeline_todos - TODO string in methods_description_template.yml: #Update the HTML below to your preferred methods description, e.g. add publication citation for this pipeline

✅ Tests passed:

Run details

  • nf-core/tools version 2.9
  • Run at 2023-07-25 09:47:22

@Midnighter
Copy link
Collaborator

I'll need to watch the video. On first recollection, I'm not convinced that subMap is anything else than a clone.

@jfy133
Copy link
Member Author

jfy133 commented Jul 21, 2023 via email

@jfy133
Copy link
Member Author

jfy133 commented Jul 21, 2023

@Midnighter
Copy link
Collaborator

Here is a quick counter example, which shows that subMap is also just a shallow copy. You can run it in the nextflow console.

a = [x: [1, 2, 3], y: 3, z: '4']
b = a.subMap(['x', 'z'])

println "a.x ${a.x} == b.x ${b.x}"  // a.x [1, 2, 3] == b.x [1, 2, 3]

a.x.add(4)

println "a.x ${a.x} == b.x ${b.x}"  // a.x [1, 2, 3, 4] == b.x [1, 2, 3, 4]

So in my opinion this will not change the situation. However, normally, just cloning maps by whatever chosen method is enough to avoid resume issues. So either, there is something happening that we're not aware of, or the pipeline is modifying a mutable meta map element in place. Both are bad options for us.

@jfy133
Copy link
Member Author

jfy133 commented Jul 23, 2023

Gah then I'm even more confused then...

I was having problems on mag with resume which was solved when I switched to the subMap method...

@jfy133
Copy link
Member Author

jfy133 commented Jul 23, 2023

Wait... I may have been overzealous with the subMaps here now I look at it... I'll check tomorrow

@jfy133
Copy link
Member Author

jfy133 commented Jul 23, 2023

Right sorry, to be clear: is the + or - that does the deep copy.

I have been using the subMap stuff to get the keys/value pairs themselves.

I think in most cases I've used everything in the context of modification but I'll double check tomorrow

@Midnighter
Copy link
Collaborator

Right sorry, to be clear: is the + or - that does the deep copy.

No, that is also equivalent to clone. Sorry, if I am adding to your confusion.

a = [x: [1, 2, 3], y: '4']
b = a + [y: '5']

println "a.x ${a.x} == b.x ${b.x}"  // a.x [1, 2, 3] == b.x [1, 2, 3]

a.x.add(4)

println "a.x ${a.x} == b.x ${b.x}"  // a.x [1, 2, 3, 4] == b.x [1, 2, 3, 4]

The subMap method is nice because one can easily get a map of specific keys. Addition is a nicely concise syntax for modifying a map while creating a new (shallow) copy.

@jfy133
Copy link
Member Author

jfy133 commented Jul 24, 2023

@Midnighter please see the thread linked in the (updated )OP . My understanding on the technical aspects was wrong but the outcome is still 'enough' 😅

Copy link
Member

@pinin4fjords pinin4fjords left a comment

Choose a reason for hiding this comment

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

So, we don't like clone() because it creates maps that point back to the original, while .subMap(), + and - all lead to properly new maps, though string values etc within them remain pointers to those in the original maps, which we're okay with. Have I got that right?

subworkflows/local/profiling.nf Outdated Show resolved Hide resolved
@jfy133 jfy133 requested a review from pinin4fjords July 25, 2023 08:29
@jfy133
Copy link
Member Author

jfy133 commented Jul 25, 2023

@pinin4fjords I think so... at least I definitely had to leave in one specific subMap even if it's duplicating the entire thing (not 💯 why, but it's related to some complex relationship between bracken and kraken2), but I've tested and it still seems to work OK now 👍

Copy link
Member

@pinin4fjords pinin4fjords left a comment

Choose a reason for hiding this comment

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

To the extent of my superficial understanding, looks good now.

Copy link
Member

@JoseEspinosa JoseEspinosa left a comment

Choose a reason for hiding this comment

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

Also from what I understand in the comments and the nice summary in slack, LGTM 🚀
Of course after addressing @maxulysse comments 😉

@jfy133 jfy133 merged commit 9fce098 into dev Jul 27, 2023
20 checks passed
@jfy133 jfy133 deleted the remove-meta-clone branch July 27, 2023 12:57
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.

5 participants