Nodes/ComfyUI_AceNodes/πŸ… Expression Eval
ComfyUI Node

πŸ… Expression Eval

A tiny calculator in the graph β€” once you install the one package it forgot

By hay86Β·Created 2 years agoΒ·Updated about a year agoΒ· 96
πŸ… Expression Eval
  • a
  • b
  • STRING
  • INT
  • FLOAT
β—„valueβ–Ί

ComfyUI gets surprisingly far with no arithmetic node in core. Then you need to compute a latent width from a height, or double a seed, or turn a CFG into a step count, and you're stuck wiring three clunky nodes together or doing mental math and hardcoding. πŸ… Expression Eval is the pack's answer: type an expression, feed it up to two variables, get back a string, an int, and a float. Simple, and - with one asterisk I'll get to in a second - genuinely useful.

How it works

You type an expression into the value field, and the node evaluates it with Python's simpleeval library. The two optional inputs, a and b, are * (any-type) ports, so you can wire almost anything into them - usually ints, floats, or strings - and reference them by name in the expression. So a + b with a=5, b=3 gives you 8 on all three outputs, and a * 1.5 with a=100 gives you 150 as a string, 150 as an int, and 150.0 as a float.

The three outputs are the same result in three skins:

  • STRING - the raw result as text, so you can pipe it into prompts or text fields.
  • INT - the result forced to an integer (it truncates, so 3.9 β†’ 3).
  • FLOAT - the result rounded to four decimal places, for feeding CFG, denoise, or weight ports.

That's it. It's simpleeval, which matters more than it sounds: unlike a raw eval(), simpleeval is a sandboxed evaluator - no imports, no function access, just math and the names you give it. You're not accidentally executing arbitrary Python by typing a bad expression.

The trap

Here's the asterisk: the node imports simpleeval, but simpleeval is not in the pack's requirements.txt. The first time you queue a workflow using this node you'll hit a clean ModuleNotFoundError: No module named 'simpleeval' while every other node in the pack works fine. One command fixes it:

pip install simpleeval

then restart ComfyUI. It's a two-line fix and the node is worth it after that.

Where you'd actually use it

The classic pattern is driving a downstream integer. Say you know your output height is 1024 and you want a width that keeps a 16:9 aspect - value a * 16 // 9, a=1024, and feed the INT output into EmptyLatentImage. Or compute a per-run seed offset, or clamp a value with min(a, 1024). It's the "do a little math mid-graph" node, and it's the natural partner to the pack's πŸ… Integer and πŸ… Float primitives.

Install

This is a node in the hay86/ComfyUI_AceNodes pack. Standard route:

cd ComfyUI/custom_nodes
git clone https://github.com/hay86/ComfyUI_AceNodes
cd ComfyUI_AceNodes
pip install -r requirements.txt

Restart ComfyUI, then add pip install simpleeval on top. Via ComfyUI Manager, search ComfyUI_AceNodes and install, then install simpleeval manually - Manager won't do it for you.

Gotchas worth remembering

The a and b inputs default to empty strings, so an expression that touches them without wiring them in will behave oddly rather than erroring clearly. And remember the INT output truncates - if your expression produces 3.99 and you need 4, either round in the expression or take the FLOAT output and convert downstream. Neither is a bug; both are just how this lightweight node draws the line.

CategoryAce Nodes

Inputs (3)

NameTypeDefaultDescription
valueSTRINGβ€”
aopt*β€”
bopt*β€”

Outputs (3)

NameTypeDescription
STRINGSTRINGβ€”
INTINTβ€”
FLOATFLOATβ€”