Package: py-aiger
pyAiger: A python library for manipulating sequential and
      combinatorial circuits.Table of ContentsAbout PyAigerInstallationBoolean Expression DSLSequential Circuit DSLSequential compositionParallel compositionCircuits with Latches/Feedback/DelayRelabelingEvaluationUseful circuitsExtraEcosystemRelated ProjectsCitingAbout PyAigerQ: How is Py-Aiger pronounced? A: Like "pie" + "grrr".Q: Why python? Aren't you worried about performance?! A: No. The goals of this library are ease of use and hackability.Q: No, I'm really concerned about performance! A: This library is not suited to implement logic solvers. For everything else, such as the creation and manipulation of circuits with many thousands of gates in between solver calls, the library is really fast enough.Q: Where does the name come from? A:Aigeris a popular circuit format. The format is used inhardware model checking,synthesis, and is supported byABC. The name is a combination of AIG (standing forAnd-Inverter-Graph) and the mountainEiger.InstallationIf you just need to useaiger, you can just run:$ pip install py-aigerFor developers, note that this project uses thepoetrypython package/dependency
management tool. Please familarize yourself with it and then
run:$ poetry installUsageimport aiger

x, y, z, w = aiger.atoms('x', 'y', 'z', 'w')

expr1 = z.implies(x & y)
expr2 = z & w

circ1 = expr1.with_output('z') \      # Get AIG for expr1 with output 'z'.
             .aig
circ2 = circ1 >> circ2                # Feed outputs of circ1 into circ2.Boolean Expression DSLWhile powerful, when writing combinatorial circuits, the Sequential
Circuit DSL can be somewhat clumsy. For this common usecase, we have
developed the Boolean Expression DSL. All circuits generated this way
have a single output.importaigerx,y,z=aiger.atoms('x','y','z')expr1=x&y# circuit with inputs 'x', 'y' and 1 output computing x AND y.expr2=x|y# logical or.expr3=x^y# logical xor.expr4=x==y# logical ==, xnor.expr5=x.implies(y)expr6=~x# logical negation.expr7=aiger.ite(x,y,z)# if x then y else z.# Atoms can be constants.expr8=x&True# Equivalent to just x.expr9=x&False# Equivalent to const False.# Specifying output name of boolean expression.# - Output is a long uuid otherwise.expr10=expr5.with_output('x_implies_y')assertexpr10.output=='x_implies_y'# And you can inspect the AIG if needed.circ=x.aig# And of course, you can get a BoolExpr from a single output aig.expr10=aiger.BoolExpr(circ)Sequential Circuit DSLimportaigerfromaigerimportutils# Parser for ascii AIGER format.aig1=aiger.load(path_to_aig1_file.aag)aig2=aiger.load(path_to_aig2_file.aag)Sequential compositionaig3=aig1>>aig2Parallel compositionaig4=aig1|aig2Circuits with Latches and Delayed FeedbackSometimes one requires some outputs to be feed back into the circuits
as time delayed inputs. This can be accomplished using theloopbackmethod. This method takes in a variable number of dictionaries
encoding how to wire an input to an output. The wiring dictionaries
with the following keys and default values:KeyDefaultMeaninginputInput portoutputOutput portlatchinputLatch nameinitTrueInitial latch valuekeep_outputTrueKeep loopbacked output as output# Connect output y to input x with delay, initialized to True.# (Default initialization is False.)aig5=aig1.loopback({"input":"x","output":"y",})aig6=aig1.loopback({"input":"x","output":"y",},{"input":"z","output":"z","latch":"z_latch","init":False,"keep_outputs":False})RelabelingThere are two syntaxes for relabeling. The first uses indexing
syntax in a nod tonotation often used variable substition in math.The syntax is the relabel method, which is preferable when one wants
to be explicit, even for those not familar withpy-aiger.# Relabel input 'x' to 'z'.aig1['i',{'x':'z'}]aig1.relabel('input',{'x':'z'})# Relabel output 'y' to 'w'.aig1['o',{'y':'w'}]aig1.relabel('output',{'y':'w'})# Relabel latches 'l1' to 'l2'.aig1['l',{'l1':'l2'}]aig1.relabel('latch',{'l1':'l2'})Evaluation# Combinatoric evaluation.aig3(inputs={'x':True,'y':False})# Sequential evaluation.sim=aig3.simulate([{'x':0,'y':0},{'x':1,'y':2},{'x':3,'y':4}])# Simulation Coroutinesim=aig3.simulator()# Coroutinenext(sim)# Initializeprint(sim.send({'x':0,'y':0}))print(sim.send({'x':1,'y':2}))print(sim.send({'x':3,'y':4}))# Unrollaig4=aig3.unroll(steps=10,init=True)Useful circuits# Fix input x to be False.aig4=aiger.source({'x':False})>>aig3# Remove output y.aig4=aig3>>aiger.sink(['y'])# Create duplicate w of output y.aig4=aig3>>aiger.tee({'y':['y','w']})Extraaiger.common.eval_order(aig1)# Returns topological ordering of circuit gates.# Convert object into an AIG from multiple formats including BoolExpr, AIG, str, and filepaths.aiger.to_aig(aig1)EcosystemStablepy-aiger-bv: Extension of pyAiger for manipulating sequential bitvector circuits.py-aiger-cnf: BoolExpr to Object representing CNF. Mostly used for interfacing with py-aiger-sat.py-aiger-past-ltl: Converts Past Linear Temporal Logic to aiger circuits.py-aiger-coins: Library for creating circuits that encode discrete distributions.py-aiger-sat: Bridge between py-aiger and py-sat.py-aiger-bdd: Aiger <-> BDD bridge.py-aiger-gridworld: Create aiger circuits representing gridworlds.py-aiger-dfa: Convert between finite automata and sequential circuits.Underdevelopmentpy-aiger-spectral: A tool for performing (Fourier) Analysis of Boolean Functions.py-aiger-abc: Aiger and abc bridge.Related ProjectspyAig: Another python library
for working with AIGER circuits.