Created
November 10, 2023 14:47
-
-
Save sterin/4fe67b29a805002e038f13ed33659b85 to your computer and use it in GitHub Desktop.
Sort AIG PIs by name
This file contains 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
# 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