Skip to content

Instantly share code, notes, and snippets.

@sterin
Created November 10, 2023 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sterin/4fe67b29a805002e038f13ed33659b85 to your computer and use it in GitHub Desktop.
Save sterin/4fe67b29a805002e038f13ed33659b85 to your computer and use it in GitHub Desktop.
Sort AIG PIs by name
# This script requires pyaig and click, they can be installed by running:
# > pip install pyaig click
# run the script as follows:
# > python sort_pis_by_name.py input.aig output.aig
# output.aig would the same as input.aig, except that the inputs would be sorted by name
# the script assumes all PIs have names
import click
from pyaig import *
@click.command()
@click.argument('input', type=click.File("rb"))
@click.argument('output', type=click.File("wb"))
def main(input, output):
src = read_aiger(input)
dst = AIG()
pis = [ (pi, src.get_name_by_id(pi)) for pi in src.get_pis() ]
M = AIG.fmap()
for pi, name in sorted(pis, key=lambda x: x[1]):
M[pi] = dst.create_pi(name)
dst.compose(src, M)
write_aiger(dst, output)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment