PsiQ / bartiq

Bartiq
https://psiq.github.io/bartiq/
Apache License 2.0
31 stars 9 forks source link

Custom repr for connection and port #54

Closed bdg221 closed 5 months ago

bdg221 commented 5 months ago

Fixes #29 This PR adds two custom repr methods for the Port and Connection classes to improve readability.

Port

@mstechly mentioned that meta should not be included and also if the size is None that it should be explicitly stated.

before:

Port(name='In_3', parent=<Routine name="alias_sampling">, direction='input', size='mu', meta={})
Port(name='In_4', parent=<Routine name="alias_sampling">, direction='input', size='1', meta={})
Port(name='out_0', parent=<Routine name="alias_sampling">, direction='output', size=None, meta={})

after:

Port(alias_sampling.#In_3, (input) size="mu")
Port(alias_sampling.#In_4, (input) size="1")
Port(alias_sampling.#out_0, (output) size="None")

Connection

before:

Connection(source=Port(name='In_1', parent=<Routine name="alias_sampling">, direction='input', size='mu', meta={}), target=Port(name='in', parent=<Routine name="had">, direction='input', size='N', meta={}), parent=<Routine name="alias_sampling">)
Connection(source=Port(name='In_2', parent=<Routine name="alias_sampling">, direction='input', size='R', meta={}), target=Port(name='In_alt', parent=<Routine name="qrom">, direction='input', size='R', meta={}), parent=<Routine name="alias_sampling">)
Connection(source=Port(name='In_3', parent=<Routine name="alias_sampling">, direction='input', size='mu', meta={}), target=Port(name='In_keep', parent=<Routine name="qrom">, direction='input', size='mu', meta={}), parent=<Routine name="alias_sampling">)

after:

Connection(alias_sampling.#In_1 -> alias_sampling.#in)
Connection(alias_sampling.#In_2 -> alias_sampling.#In_alt)
Connection(alias_sampling.#In_3 -> alias_sampling.#In_keep)