discopy icon indicating copy to clipboard operation
discopy copied to clipboard

More helpful `does_not_compose` error message

Open kinianlo opened this issue 3 years ago • 2 comments

Currently, when one tries to compose two Diagrams that do not compose, an error message displays the two diagrams. E.g.

A = Box('A', Ty(), Ty('s'))
B = Box('B', Ty('n'), Ty())
A >> B

gives AxiomError: A does not compose with B. In this case, the error message is helpful, as we can immediately see that the problem is due to Ty('n') != Ty('s').

However, when the two diagrams are complicated, it is not very helpful to see all these:

AxiomError: Cap(n.r, n) >> Id(n.r) @ Cap(s, s.l) @ Id(n) >> Id(n.r @ s @ s.l @ n) @ too >> Id(n.r @ s @ s.l @ n @ n.r @ s @ s.l @ n) @ large. >> Id(n.r @ s @ s.l @ n @ n.r @ s @ s.l) @ Cup(n, n.r) @ Id(s) >> Id(n.r @ s @ s.l @ n @ n.r @ s) @ Cup(s.l, s) >> Id(n.r @ s @ s.l) @ Cup(n, n.r) @ Id(s) >> Id(n.r @ s) @ Cup(s.l, s) does not compose with The @ Id(n.l @ s) >> Id(n @ n.l) @ trophy @ Id(s) >> Id(n @ n.l @ n @ n.l) @ doesn't @ Id(s) >> Id(n @ n.l @ n @ n.l @ n) @ fit @ Id(s) >> Id(n @ n.l @ n @ n.l @ n @ n.r @ s @ p.l) @ into @ Id(s) >> Id(n @ n.l @ n @ n.l @ n @ n.r @ s @ p.l @ p @ n.l) @ the @ Id(s) >> Id(n @ n.l @ n @ n.l @ n @ n.r @ s @ p.l @ p @ n.l @ n @ n.l) @ brown @ Id(s) >> Id(n @ n.l @ n @ n.l @ n @ n.r @ s @ p.l @ p @ n.l @ n @ n.l @ n @ n.l) @ suitcase @ Id(s) >> Id(n @ n.l @ n @ n.l @ n @ n.r @ s @ p.l @ p @ n.l @ n @ n.l @ n @ n.l @ n) @ because @ Id(s) >> Id(n @ n.l @ n) @ Cup(n.l, n) @ Id(n.r @ s @ p.l @ p @ n.l @ n @ n.l @ n @ n.l @ n @ s.r @ n.r.r @ n.r @ s @ s.l @ s) >> Id(n) @ Cup(n.l, n) @ Id(n.r @ s @ p.l @ p @ n.l @ n @ n.l @ n @ n.l @ n @ s.r @ n.r.r @ n.r @ s @ s.l @ s) >> Id(n @ n.r @ s @ p.l @ p @ n.l @ n @ n.l @ n) @ Cup(n.l, n) @ Id(s.r @ n.r.r @ n.r @ s @ s.l @ s) >> Id(n @ n.r @ s @ p.l @ p @ n.l @ n) @ Cup(n.l, n) @ Id(s.r @ n.r.r @ n.r @ s @ s.l @ s) >> Id(n @ n.r @ s @ p.l @ p) @ Cup(n.l, n) @ Id(s.r @ n.r.r @ n.r @ s @ s.l @ s) >> Id(n @ n.r @ s) @ Cup(p.l, p) @ Id(s.r @ n.r.r @ n.r @ s @ s.l @ s) >> Id(n @ n.r @ s @ s.r @ n.r.r @ n.r @ s) @ Cup(s.l, s) >> Id(n @ n.r) @ Cup(s, s.r) @ Id(n.r.r @ n.r @ s) >> Id(n) @ Cup(n.r, n.r.r) @ Id(n.r @ s) >> Cup(n, n.r) @ Id(s).

A helpful error message in these situations should help the users to figure out why don't the diagrams compose. I suggest that one way to make the message clearer is to also include A.cod and B.dom in the error message. E.g.

A = Box('A', Ty(), Ty('s'))
B = Box('B', Ty('n'), Ty())
A >> B

AxiomError: A does not compose with B. Codomain Ty('s') is not compatible with domain Ty('n')

kinianlo avatar Feb 12 '22 10:02 kinianlo

I agree

y-richie-y avatar Feb 14 '22 07:02 y-richie-y

Thanks for your feedback! I'm working on a v1.0 where the error management will be refactored. Before that's merged with the main branch and released, even the smallest pull requests with small improvements to the error messages would be very much welcome.

toumix avatar Feb 23 '22 10:02 toumix

Resolved by #82

y-richie-y avatar Sep 14 '22 09:09 y-richie-y