Last active
April 29, 2025 14:11
-
-
Save robsyme/ec3d862c0f0d2af5713e5e7fb63782af to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| nextflow.preview.topic = true | |
| workflow { | |
| def statham = new groovy.json.JsonSlurper() | |
| Channel.topic('model_updates') | |
| .tap { updates } | |
| .map { path -> statham.parseText(path.text) } | |
| .until { obj -> obj?.score > 100 } | |
| .tap { limit } | |
| .last() | |
| .view { model -> "Final model: $model" } | |
| Setup() | |
| Model(updates, limit) | |
| } | |
| process Model { | |
| publishDir 'results', mode: 'copy', saveAs: { "out.iteration_${task.index}.json" } | |
| input: | |
| path("start.json") | |
| val(limiter) | |
| output: | |
| path("updated.json"), topic: model_updates | |
| script: | |
| """ | |
| #!/usr/bin/env python | |
| import json | |
| import random | |
| # Read in updated.json | |
| with open('start.json') as f: | |
| data = json.load(f) | |
| # Add a new step object | |
| new_step = { | |
| "step": data['step'] + 1, | |
| "score": data['score'] + random.randint(1, 10) | |
| } | |
| # Pretty print the updated data to updated.json | |
| with open('updated.json', 'w') as f: | |
| json.dump(new_step, f) | |
| """ | |
| } | |
| process Setup { | |
| output: path("start.json"), topic: model_updates | |
| script: | |
| """ | |
| echo '{ "step": 0, "score": 0 }' > start.json | |
| """ | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment