-
Notifications
You must be signed in to change notification settings - Fork 256
Node: Power Puter
The Power Puter is an incredibly powerful, advanced node that allows you to evaluate python-like expressions and return primitives or instances through its output.
It was originally created to coalesce several other individual nodes across various node packs to allow for string concatenation or simple math expressions and morphed into a full blown 'puter capable of lookups, comparison, decision trees, formatting, list comprehension, and more.
The Power Puter node consists of an fancy outputs widget to choose the number of outputs and their type. Each output can be STRING, INT, FLOAT or BOOL in the workflow to more easily connect to other nodes of that type and each of these types will coerce the corresponding value from the code input to this type (or raise an error if incompatible). Additionally, you can select a wildcard/any type of * which should allow it to be connected to anything and it will return the type exactly as specified in your code; whether one of the above primitive types, or forwarding an input value, etc.
The fancy part of the outputs widget is adding/selecting more than one output. If adding more than one output, then the value from the code input must be tuple where each item corresponds to the output. For instance, outputs STRING, INT, FLOAT should have a return type like: return ('foo', 3, 4.2).
Note: If only one output is selected, then the output value will be the return type as-is, even if it's a tuple.
The Power Puter node's code box allows you to write python-like code to be evaluated and returned.
- The return value will be the last returned value of the code block, or from an explicit
returnstatement. - The code box allows for only explicit types to be instantiated and "naked" calls to be made.
- Once an instance is available, most attributes and calls are available to be made off it.
- If there are multiple outputs, the return value must be a tuple where each item corresponds to the output.
The inputs of the Power Puter, hardcoded as a, b, c... x, y, z can have the values fed into it available for use as those named variables. (Note, renaming an input does not change the variable name available in the code). In addition to the value available, we can look up the connected node.
There's a controlled list of functions available for your code that forward to built-in or naked function calls.
| Fn Name | Equivalent | Cacheable | Description |
|---|---|---|---|
round |
round |
✅ | Rounds an input number. A second argument can provide the precision. |
ceil |
math.ceil |
✅ | Rounds an input number up. |
floor |
math.floor |
✅ | Rounds an input number down. |
sqrt |
math.sqrt |
✅ | Returns the square root. |
min |
min |
✅ | Returns the smallest of multiple inputs. |
max |
max |
✅ | Returns the largest of multiple inputs. |
random_int |
random.randint |
❌ | Returns a random integer between two provided numbers, inclusive. |
random_choice |
random.choice |
❌ | Returns a random element from a provided list. |
re |
re.compile |
✅ | Compiles a regular expression pattern into a regex object. |
len |
len |
✅ | Returns the length of the input. |
int |
int |
✅ | Returns an integer cast from the input. |
float |
float |
✅ | Returns a float cast from the input. |
str |
str |
✅ | Returns a string cast from the input. |
bool |
bool |
✅ | Returns a boolean cast from the input. |
list |
list |
✅ | Returns a list cast from the input. |
tuple |
tuple |
✅ | Returns a tuple cast from the input. |
print |
print |
✅ | Prints the input to the terminal. |
purge_vram |
none | ✅ | Calls gc.collect(), torch.cuda.empty_cache() (when cuda is available), torch.cuda.ipc_collect() (when cuda is available), and when the purge_models is not False calls comfy.model_management.unload_all_models() and comfy.model_management.soft_empty_cache(). |
input_node |
none | ✅ | Returns the node data (dict) for a connected node as found in the current prompt data. Input is the input name, such as 'a' or 'b' etc. |
node |
none | ❌ | Returns a the node data (dict) found in the current prompt data. Input can be a node id ( int) a node title (str) or a regular expression object to match against a node title (use re(r'^My Title.*')
|
nodes |
none | ❌ | Returns a list of node data (dict) of nodes found in the current prompt data. Input can be a node id ( int) a node title (str) or a regular expression object to match against a node title (use re(r'^My Title.*')
|
batch |
none | ✅ | Creates a single batched IMAGE or LATENT from args. Can be called with many args so long as all are IMAGE or LATENT. |
When you have a reference to a Power Lora Loader node (from a node_input, node or nodes call above) you also have these handier functions available:
| Fn Name | Description |
|---|---|
loras() |
Returns a list of the lora data for enabled loras on the node. |
triggers(max_each=1) |
Returns a list of the trigger words for all enabled loras on the node. Set max_each optionally to return more words per enabled lora (defaults to 1) |
You'll notice emoji's above in a "Cachable" column. Using a method marked with ❌ there means the Power Puter won't ever cache the result, as the operation is either random or depends on looking up a node that the Power Puter cannot determine if it's been changed or not. Because of this, the Power Puter will always run. This is fine if the Power Puter is used with trivial or fast nodes downstream; however these functions should be avoided if it's upstream from KSamplers, etc. There are more verbose workarounds to each above.
A the core, the Power Puter can evaluate simple math expressions, or concatenate strings.


You can also use f-string for formatted string:

You can also handle complex types. For instance, you could use this to return the width or height of an image (though, there are dedicated nodes for that as well):

You can even re-create (and enhance) "Get Image Size" nodes, etc with multiple outputs:

You can grab data from a connected node as well and get its inputs, data, class_type, id, etc. And, when it's a special node noted above, like Power Lora Loader, there's the ability to do even more.
For instance, here's an example grabbing all the enabled lora inputs from a connected Power Lora Loader, and outputting the data as a <lora:...> notation used in prompting:

And here's one using the special triggers() function, which looks up the trigger words in the enabled loras.

The possibilities are pretty limitless now. You could recreate switch nodes, lookup widgets across the prompt, grab values, gate data, etc.