<jupyter_start><jupyter_text>Let's play around with the graphviz backend. Shift registerThis example is taken from the shift_register notebook.<jupyter_code>from magma import *
from magma.primitives import DefineRegister

N = 4
Register4 = DefineRegister(4)
T = Bits(N)

class ShiftRegister(Circuit):
    name = "ShiftRegister"
    IO = ["I", In(T), "O", Out(T), "CLK", In(Bit)]
    @classmethod
    def definition(io):
        regs = [Register4() for _ in range(N)]
        [wire(io.CLK, reg.clk) for reg in regs]  # TODO: Clean up this clock wiring
        wire(io.I, getattr(regs[0], "in"))
        braid(regs, foldargs={"in":"out"})
        wire(regs[-1].out, io.O)<jupyter_output><empty_output><jupyter_text>Now let's visualize our `ShiftRegister` type.<jupyter_code>ShiftRegister<jupyter_output><empty_output><jupyter_text>For some separate reason, the visualization is slightly broken (outputs aren't wired up) for a placed circuit / instance (?) like `ShiftRegister()` below.It's not graphviz-specific, I think: the same issue shows up in firrtl and verilog compile output.<jupyter_code>ShiftRegister()<jupyter_output><empty_output><jupyter_text>Simple ALUAnother example, taken from the Chisel examples folder.<jupyter_code>from functools import reduce

def one_hot_mux(conds, inputs):
    outputs = []
    for cond, inp in zip(conds, inputs):
        outputs.append(inp & uint([cond for _ in range(len(inp))]))
    return reduce(lambda x, y: x | y, outputs)


class SimpleALU(Circuit):
    name = "SimpleALU"
    IO = ["a", In(UInt(4)), "b", In(UInt(4)), "opcode", In(UInt(2)), "out", Out(UInt(4))]
    
    @classmethod
    def definition(io):
        is_op0 = io.opcode == uint(0, n=2)
        is_op1 = io.opcode == uint(1, n=2)
        is_op2 = io.opcode == uint(2, n=2)
        is_op3 = io.opcode == uint(3, n=2)
        op0_out = io.a + io.b
        op1_out = io.a - io.b
        op2_out = io.a
        op3_out = io.b
        wire(io.out, one_hot_mux([is_op0, is_op1, is_op2, is_op3], [op0_out, op1_out, op2_out, op3_out]))
SimpleALU<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13618864292589028, 'fraction_numerical': 0.016361886429258902, 'mean_word_length': 3.880281690140845, 'pattern_counts': {'":': 1, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '360318', 'license': 'MIT', 'n_tokens_mistral': 764, 'n_tokens_neox': 746, 'n_words': 191, 'path': 'notebooks/examples/graphviz.ipynb', 'repo_name': 'David-Durst/magma', 'size': '2078'}