Generators¶
The module provides generation helpers for reproducible random dataset creation and structured arithmetic/control benchmarks.
Random AIG Generation¶
Use random_aig() for reproducible one-shot generation.
1from aigverse.generators import random_aig
2
3# One-shot random AIG with fixed size
4single = random_aig(num_pis=4, num_gates=12, seed=42)
5print(single.num_pis, single.num_gates)
4 12
Python-Side Batching¶
Batching is intentionally kept on the Python side to keep experiment orchestration reproducible and easy to compose
with downstream data science and ML code. For fixed-size datasets, call
random_aig() repeatedly with fixed num_pis and num_gates.
Note
random_aig() does not guarantee a fixed num_pos across seeds:
mockturtle’s random topology can leave a different number of dangling nodes depending on the sampled structure.
As a result, repeated calls with identical num_pis/num_gates may still produce different output counts if the seed
varies. For ML training loops, when you need a uniform label shape, you can filter generated examples by num_pos or
resample seeds until num_pos matches your target.
1from aigverse.generators import random_aig
2
3batch_fixed = [random_aig(num_pis=4, num_gates=12, seed=1000 + i) for i in range(8)]
4print(len(batch_fixed), batch_fixed[0].num_pis, batch_fixed[0].num_gates)
8 4 12
For size-diverse datasets, sample sizes in Python and pass them to
random_aig().
1import random
2
3from aigverse.generators import random_aig
4
5rng = random.Random(7)
6
7dataset = [
8 random_aig(
9 num_pis=rng.randint(3, 5),
10 num_gates=rng.randint(10, 16),
11 seed=2000 + i,
12 )
13 for i in range(8)
14]
15
16print([(aig.num_pis, aig.num_gates) for aig in dataset])
[(4, 11), (4, 15), (3, 10), (5, 10), (4, 14), (3, 14), (3, 10), (3, 13)]
Structured Benchmark Builders¶
Complete benchmark networks of arithmetic and control circuits of arbitrary bitwidth can be created via respective high-level generator functions.
1from aigverse.generators import ripple_carry_adder, carry_lookahead_adder
2
3rca4 = ripple_carry_adder(bitwidth=4)
4print(f"RCA: I/O: {rca4.num_pis}/{rca4.num_pos}, gates: {rca4.num_gates}")
5cla4 = carry_lookahead_adder(bitwidth=4)
6print(f"CLA: I/O: {cla4.num_pis}/{cla4.num_pos}, gates: {cla4.num_gates}")
RCA: I/O: 8/5, gates: 24
CLA: I/O: 8/5, gates: 36
Control Generators¶
Control builders follow the same high-level model.
1from aigverse.generators import binary_decoder, multiplexer
2
3mux = multiplexer(bitwidth=4)
4print(f"MUX: I/O: {mux.num_pis}/{mux.num_pos}, gates: {mux.num_gates}")
5
6decoder = binary_decoder(num_select_bits=4)
7print(f"Decoder: I/O: {decoder.num_pis}/{decoder.num_pos}, gates: {decoder.num_gates}")
MUX: I/O: 9/4, gates: 12
Decoder: I/O: 4/16, gates: 24
Available structured builders include
ripple_carry_adder(),
carry_lookahead_adder(),
sideways_sum_adder(),
ripple_carry_multiplier(),
multiplexer(), and
binary_decoder().