byuccl / spydrnet-tmr

TMR utilities for the SpyDrNet project
https://byuccl.github.io/spydrnet-tmr/
BSD 3-Clause "New" or "Revised" License
4 stars 2 forks source link

EDIF netlists are not reproducible #19

Open gsmecher opened 2 years ago

gsmecher commented 2 years ago

SpyDrNet-TMR produces different EDIF netlists from run to run (Python 3.10.4). Repeatability is desirable for traceable builds and automated CAD flows.

For example:

netlist = sdn.load_example_netlist_by_name('fourBitCounter')
uniquify(netlist)

hinstances_to_replicate = list(netlist.get_hinstances(
    recursive=True,
    filter=lambda x: x.item.reference.is_leaf()))
instances_to_replicate = list(x.item for x in hinstances_to_replicate)

# Don't replicate any ports?
hports_to_replicate = []
ports_to_replicate = []

# Insertion points
insertion_points = find_after_ff_voter_points(netlist, [*hinstances_to_replicate, *hports_to_replicate], XILINX)

replicas = tmr.apply_nmr([*instances_to_replicate, *ports_to_replicate], 3, name_suffix='TMR', rename_original=True)
voters = tmr.insert_organs(replicas, insertion_points, XilinxTMRVoter(), 'VOTER')

sdn.compose(netlist, "fourBitCounter_tmr.edif")

If I run this command repeatedly, the generated EDIF is equivalent but permuted. Speculating, but the underlying cause is probably the appearance of memory addresses in the __hash__ exported by SpyDrNet IR classes like OuterPin. As a result, dictionary order is different from run to run, even though iterating through dictionary keys is determinstic in Python from 3.6 onwards and is considered a language feature from 3.7 onwards.

The __hash__ should identify instances using source location from the input netlist, if possible. (The ability to trace an IR instance back to source netlist is presumably useful on its own.)

Easy to complain, harder to implement - I am leaving this here in the hopes it's helpful, and with no expectation that anyone is going to rush out and implement it for me. Thanks for all your hard work on SpyDrNet and SpyDrNet-TMR.

best, Graeme

jacobdbrown4 commented 2 years ago

Thanks for submitting this issue. I used your script and was able to replicate the issue you're talking about. Determinism is definitely one of our goals so we will look into this.