fraig_store: restore the PI order when the name comparison fails - #538
Open
marcelwa wants to merge 1 commit into
Open
fraig_store: restore the PI order when the name comparison fails#538marcelwa wants to merge 1 commit into
marcelwa wants to merge 1 commit into
Conversation
Abc_NtkCompareSignals() sorts the PIs, POs and boxes of both networks by name
before comparing them. That is deliberate and is what lets fraig_store accept
two networks that use the same names in a different order.
When the names do not match, though, the comparison fails, Abc_NtkFraigStore()
resets the store and keeps the incoming network -- which by then has already
been sorted. The network that ends up in the store is a permutation of the one
the caller read in, and nothing reports it. The two lines printed on that path
say the store was reset; they do not say the interface changed.
Sorting is by name as a string, so numeric port names are where it shows up
worst: 1, 2, ..., 10 sort as 1, 10, 2, 3, ... With the EPFL cavlc benchmark and
its published reference netlist, whose ports are named "1".."10",
read_aiger cavlc.aig; strash; fraig_store
read_blif cavlc_size.blif; strash; fraig_store
fraig_restore; write_blif out.blif
gives an out.blif whose inputs are ordered 1, 10, 2, 3, ... instead of
1, 2, 3, ..., 10. It has the right number of inputs and outputs, it passes
Abc_NtkCheck(), and "cec -n out.blif cavlc.aig" reports a counterexample.
Save the three vectors before the comparison and put them back if it fails,
then rebuild vCis/vCos with Abc_NtkOrderCisCos(). The success path is
untouched, and so is every path where the names already agree -- those never
reach Abc_NtkCompareSignals(), since Abc_NodeCompareCiCo() has already
returned 1.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #537, which I filed before I had the mechanism right. It is not PI invention in
Abc_NtkAppendToCone()— that branch is never reached here. It is PI reordering, one level up, and it has a two-line fix.What happens
Abc_NtkCompareSignals()callsAbc_NtkOrderObjsByName()on both networks, whichqsortsvPis,vPosandvBoxesin place before the comparison. That is deliberate: it is what letsfraig_storeaccept two networks that use the same port names in a different order.When the names genuinely differ, the comparison fails and
Abc_NtkFraigStore()takes this path:The store is reset and
pNtkis kept — butpNtkhas already been sorted by the comparison that failed. What goes into the store is a permutation of the network the caller read in. The two printed lines say the store was reset; nothing says the interface changed.Sorting is by name as a string, so numeric port names are the worst case:
1, 2, …, 10sorts to1, 10, 2, 3, ….Reproducing
EPFL
cavlcand its published reference netlist, whose ports are named1…10:Right number of inputs and outputs, passes
Abc_NtkCheck(), wrong function. The reference netlist on its own is equivalent — only going throughfraig_storebreaks it, and only because the store then discards it and keeps the sorted copy.I ran into this building choice networks out of differently-named implementations of the same circuit; 9 of 20 merges came back non-equivalent with plausible-looking area and depth. The workaround is to round-trip everything through
write_aiger/read_aigerfirst so names are regenerated positionally, but the sort surviving a failed comparison seemed worth fixing rather than working around.The change
Save
vPis/vPos/vBoxesbefore the comparison, put them back if it fails, and rebuildvCis/vCoswithAbc_NtkOrderCisCos().Deliberately narrow:
Abc_NtkCompareSignals()at all, becauseAbc_NodeCompareCiCo()has already returned 1.Checks
Built clean. Against the EPFL suite:
cavlcwith the mismatched reference: PI order now0=1 1=2 2=3 …, andcec -nreports equivalent.ctrl,arbiter,max— names already agree — merge and verify exactly as before.fraig_store/fraig_restore, both unchanged.Happy to add the name-mismatch case to a regression test if you have a preferred place for it.