add ListRandomSeeds (#11)

* create node ListRandomSeeds

* adjust XY Plot: Queue and GenericQueue to store input lists at first round
This commit is contained in:
Bug, Ltd.
2025-01-28 12:00:19 +01:00
committed by GitHub
parent d0e629a75e
commit 078e669467
4 changed files with 60 additions and 2 deletions
+1
View File
@@ -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",
+39
View File
@@ -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))
+12 -2
View File
@@ -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))
+8
View File
@@ -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')