Formula Data Generator
Type an equation, get a labelled dataset
- model
- X
- y
- dataset
Most nodes on this site want a latent, a checkpoint or a mask. This one wants an equation. Formula Data Generator (CdlFormulaDataGen) lives in ComfyDL's d2l/Datasets category: it samples a feature matrix, evaluates the formula you typed on every row, adds the noise you asked for, and hands back X, y and a ready DATASET.
The pack explains the node. ComfyDL is ComfyUI-as-a-deep-learning-workbench: built on the Dive into Deep Learning codebase, 128 of its own nodes under d2l/* covering datasets, losses, optimisation, plots, CNNs and small language models. Tabular and toy-model work, not pictures. Your usual data source there is a CSV/XLSX/DB reader, and they all emit the same DATASET; this node is the file-free path. The two production-style regression templates start with it (the from-scratch teaching one uses the pack's fixed y = Xw + b generator instead).
The formula is a real (small) language
Formulas are Python-style math over variables x0, x1, …. The stock template uses 2 + 3*x0 - 1.5*x1 + 0.5*x2. The feature count is one more than the highest index you reference, so a formula that touches only x0 and x2 still produces three columns - x1 just doesn't move the label.
Function whitelist: sin, cos, tan, asin, acos, atan, sinh, cosh, tanh, exp, log, log2, log10, sqrt, abs, sign, sigmoid, floor, ceil, round, min, max, pow, plus the constants pi and e. Operators: + - * / // % ** and unary ±. That's the whole grammar - no attributes, indexing, lambdas, comprehensions, keyword arguments or string/bool literals. The expression is AST-whitelisted before it's evaluated, with almost every builtin stripped out. A constant formula with no x at all is rejected, correctly: a label that never varies teaches a model nothing.
Sampling, noise, and the seed
x_min / x_max define the window. uniform samples flat U[x_min, x_max]; normal samples N(mean=(x_min+x_max)/2, std=(x_max-x_min)/6), which puts roughly 99.7% of points inside the window and lets the rest fall outside - it isn't a clipped uniform. noise is none, gaussian (N(0, noise_std)) or uniform (±noise_std); uniform at the same number is quieter in RMS terms than gaussian. The noise scale is ignored when noise=none.
Evaluation is vectorised - the formula runs once on the whole matrix. seed drives a local torch generator, so output is deterministic per seed without disturbing ComfyUI's global RNG. Same seed, same table, every queue. Leave the widget's control_after_generate on fixed unless you genuinely want the data to move between runs.
If the formula hits its domain (log of a non-positive number, divide by zero) or noise pushes labels to inf/nan, the node raises instead of handing you a poisoned training set.
Model mode: the digital twin
Wire an nn_model into the optional model slot and the formula is bypassed: labels become model(X) + noise, with the feature width inferred from the model's first 2-D weight. That's the round trip the pack is built around: train a regressor, reload the .pt later with Regression Model Load, then re-simulate unlimited fresh data from the model without retraining anything.
Inputs and outputs
Widgets that matter: formula, num_examples (1 to 1,000,000), x_min/x_max, sampling, noise, noise_std, seed. Outputs: X (n × k TENSOR), y (n × 1 TENSOR), and dataset. Wire dataset into Regression Train's dataset slot - it carries both tensors plus provenance (source, formula, noise, seed) and wins over X/y when everything is connected. The bare tensors are there for nodes that only speak TENSOR.
Install
ComfyUI Manager → search ComfyDL. The pack isn't on the Comfy Registry yet (its pyproject.toml still ships an empty PublisherId), so if search finds nothing, use Manager's Install via Git URL, or do it by hand:
cd ComfyUI/custom_nodes
git clone https://github.com/Cynthia-lxx/ComfyDL
pip install -r ComfyDL/requirements.txt
Restart ComfyUI; the nodes land in the d2l/* categories. Dependencies are just matplotlib, IPython and matplotlib-inline - no torch pin, no model downloads. Do not skip that pip line, though: the pack imports matplotlib at module load, so a missing dependency kills the whole pack and you get no nodes at all, not just broken plots. There's also ComfyDL_UI, a ComfyUI fork with the pack built in, if you'd rather not touch your main environment.
Common issues
- "Unknown name 'x3'" - you used a variable beyond the feature count you intended, or something that isn't a whitelisted function. The error names the offender.
- "formula is empty" - the node wants at least one
xvariable referenced. - Non-finite labels - almost always
log/sqrtover a range that crosses zero. Narrow the window or change the function. - Empty community lore. ComfyDL has essentially no discussion footprint - a search of the r/comfyui, r/StableDiffusion and r/civitai corpus for the pack name returns nothing. Nobody's documenting the weird corners for you, which sounds worse than it is: the source is short and explicit, and the shipped templates (Templates → ComfyDL Examples) show the wiring.
Inputs (9)
| Name | Type | Default | Description |
|---|---|---|---|
| formula | STRING | 2 + 3*x0 - 1.5*x1 + 0.5*sin(6*x0) | — |
| num_examples | INT | 10001–1000000 | — |
| x_min | FLOAT | -3.0-1000000–1000000 | — |
| x_max | FLOAT | 3.0-1000000–1000000 | — |
| sampling | COMBO | uniform | 2 options: uniform, normal |
| noise | COMBO | gaussian | 3 options: none, gaussian, uniform |
| noise_std | FLOAT | 0.100–1000 | — |
| seed | INT | 00–99999 | — |
| modelopt | nn_model | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| X | TENSOR | — |
| y | TENSOR | — |
| dataset | DATASET | — |