-
Notifications
You must be signed in to change notification settings - Fork 651
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
How to use custom objects and have tasks cached #1934
Comments
Unfortunately, now the serialisation with custom objects does not work properly because NF uses Kryo under the hood for better performance that requires some custom code to register the object serialiser. Needs to be improved. |
Happy to help improve it if you point me to the place as I think this type of pattern will be common for me going forward. Just like named tuples and attrs/data classes in Python. |
The relevant section is this nextflow/modules/nextflow/src/main/groovy/nextflow/util/SerializationHelper.groovy Lines 206 to 219 in d959bfd
I think it could be introduced a User classes should just implement such |
Would something like this help @nh13 ? We have also reverted to passing all of the sample metadata around in a Groovy Map, however, the file path elements change dynamically through the workflow and are staged through the standard Nextflow mechanism which keeps the The |
Thanks @drpatelh but I think I’d prefer custom objects where I can centralize methods that return paths or the like that are based off the metadata. I’m not sure about your implementation, but I want to avoid storing data in an unstructured way or anything similar to Python dictionaries. I want named members and the like in one place for clarity. |
Fair enough. I am using named members too which are instantiated at the module level like here but your approach is probably a better one. In fact it may be able to replace our current functionality which is mostly a workaround so be interested to see how your final implementation looks :) Edited: My bad, wrong link above but similar concept for passing around module |
Ok, i've a patch for this. I'll upload in the following days. |
Made some progress on this 👉 40a66ac Essentially it requires the use of an annotation @ValueObject
class MyData {
String foo
String bar
}
process foo {
input:
val x from ( new MyData(foo:'one',bar:'two') )
output:
file 'x.txt'
script:
"""
echo "$x.foo $x.bar" > x.txt
"""
} it also automatically implements |
@pditommaso immutability would be very nice. It gets us a lot closer to case classes like in Scala. |
Let's do it, immutable and autoclonable 8dfaadf |
This has been included in version @ValueObject
class MyData {
String foo
String bar
} The class is made automatically, serializable, immutable and cleanable. Therefore attributes cannot be modified. The object needs to be created using named parameter constructor eg def data = new MyDaya(foo:'this', bar:'that') to modify the one more attributes a copy needs to be created as shown below: def another = data.copyWith(foo:'Hello') |
This appears to not work when defining the class in a Running off of edge I get the following error when defining a class
However, the following works.
|
Since it's a plain groovy file adds |
|
The above works with |
The codes below still don't work:
The log says:
|
@kaizhang see this solution: #2085 (comment) import groovy.transform.Immutable
import nextflow.io.ValueObject
import nextflow.util.KryoHelper
@ValueObject
@Immutable(copyWith=true, knownImmutables = ['foo', 'bar'])
class MyData {
static {
// Register this class with the Kryo framework that serializes and deserializes objects
// that pass through channels. This allows for caching when this object is used.
KryoHelper.register(MyData)
}
String foo
String bar
} |
@nh13 That works, thank you! |
Sometimes it's useful to have a container class for metadata that I can pass around in channels along with the actual paths. For example,
If I use such a class, none of tasks are cacheable that use it. What do I have to do to make it cacheable? I couldn't find information about this in the docs.
The text was updated successfully, but these errors were encountered: