diff --git a/node_list.json b/node_list.json index 8b5405b..dbbf286 100644 --- a/node_list.json +++ b/node_list.json @@ -10,6 +10,7 @@ "List: from Elements (lab)": "Create a list from any number of individual elements", "List: Merge (lab)": "Merge any number of lists into one", "List: Limit (lab)": "Limit list to a given size", + "List: Random Seeds (lab)": "Return a list of random seeds", "Output Config: Load (lab)": "Load a local JSON or YAML config file, and dynamically generate outputs", "Output Config: Retrieve (backend) (lab)": "Retrieve a JSON or YAML config file from backend, and dynamically generate outputs", "Generic Queue (lab)": "Loop through all values of input list, and send them to output", diff --git a/src/python/nodes/list.py b/src/python/nodes/list.py index 870d25c..0db22d8 100644 --- a/src/python/nodes/list.py +++ b/src/python/nodes/list.py @@ -1,4 +1,6 @@ import hashlib +import math +import random from ..collection.register_nodes import register_node @@ -383,3 +385,40 @@ class ListLimit: output = list[-nb_elements:] return (output, len(output)) + + +@register_node('List: Random Seeds', 'list') +class ListRandomSeeds: + def __init__(self): + pass + + @classmethod + def INPUT_TYPES(s): + return { + 'required': { + 'count': ( + 'INT', + {'default': 1, 'min': 1, 'tooltip': 'number of random seeds'}, + ), + }, + } + + FUNCTION = 'run' + RETURN_TYPES = ('LIST', 'INT') + RETURN_NAMES = ('list', 'count') + OUTPUT_TOOLTIPS = ( + 'list of random seeds', + TOOLTIP_OUTPUT_COUNT, + ) + DESCRIPTION = 'Return a list of random seeds.' + + # ensure the list is regenerated + @classmethod + def IS_CHANGED(cls, **kwargs): + return float('NaN') + + def run(self, count): + values = [] + for i in range(0, count): + values.append(math.floor(random.randrange(0, 0xFFFFFFFFFFFFFFFF))) + return (values, len(values)) diff --git a/src/python/nodes/plot.py b/src/python/nodes/plot.py index bca6559..a7d4c26 100644 --- a/src/python/nodes/plot.py +++ b/src/python/nodes/plot.py @@ -82,6 +82,9 @@ class XYPlotQueue: ) DESCRIPTION = 'Loop through all values of dim1, optionally combined with dim2 values, and send them to outputs.\nIMPORTANT: for a given dim1 value, all dim2 values are first iterated, before going to the next dim1 value.\nSo it is advised to associate slow operations (e.g. loading checkpoints) to dim1, to ensure better performance.' + dim1 = [] + dim2 = [] + def run( self, dim1: list[str], @@ -90,8 +93,15 @@ class XYPlotQueue: index: int, dim2: list[str] = [''], ): - if len(dim2) == 0: - dim2 = [''] + # store the input lists, to allow using input nodes that change at each prompt (ex. ListRandomSeeds) + if index == 0: + if len(dim2) == 0: + dim2 = [''] + self.dim1 = dim1 + self.dim2 = dim2 + else: + dim1 = self.dim1 + dim2 = self.dim2 # to simplify code below size = (len(dim1), len(dim2)) diff --git a/src/python/nodes/queue.py b/src/python/nodes/queue.py index aba1e85..fb2e092 100644 --- a/src/python/nodes/queue.py +++ b/src/python/nodes/queue.py @@ -33,7 +33,15 @@ class GenericQueue: OUTPUT_TOOLTIPS = ('current value (not typed)', 'current index', 'total elements') DESCRIPTION = 'Loop through all values of input list, and send them to output.' + input_list = [] + def run(self, input_list: list[Any], index: int): + # store the input list, to allow using input nodes that change at each prompt (ex. ListRandomSeeds) + if index == 0: + self.input_list = input_list + else: + input_list = self.input_list + total = len(input_list) if total == 0: raise Exception('Empty input list')