Closed kinianlo closed 1 day ago
Thanks a lot for this PR @kinianlo ! This is definitely something that needs fixing.
Your approach would work for circuits, but could be expanded to extend this behaviour to all functors (not just ansatze).
I'd recommend this be implemented by adding your logic in a apply_functor
method added to the Daggered
class in grammar.py.
Daggered class is here: https://github.com/CQCL/lambeq/blob/main/lambeq/backend/grammar.py#L1547
Example apply_functor
from existing Box
: https://github.com/CQCL/lambeq/blob/main/lambeq/backend/grammar.py#L447
This would yield the same behaviour for ansatze, and across functors applied to daggered boxes.
@nikhilkhatri Thank you for the suggestion! I I’ve tried to implement that but there is a problem at its current state: Diagrammable
does not have a dagger()
method. Is Diagrammable
supposed to have a dagger()
method? Otherwise the logic should be applied to specific subclasses of Diagrams with a dagger()
defined?
@kinianlo I think it makes sense to add a dagger
signature to Diagrammable
.
Something as simple as the following should work:
def dagger(self) -> Diagrammable:
"""Implements conjugation of diagrams."""
@kinianlo I think it makes sense to add a
dagger
signature toDiagrammable
.Something as simple as the following should work:
def dagger(self) -> Diagrammable: """Implements conjugation of diagrams."""
Copied and pasted👍
It would be nice to have
CircuitAnsatz
acting as a dagger functor, that isCurrently this is not true. For instance:
Note that the symbols of
circ2
are completely different to those incirc1
. The ansatz simply takes the dagger as part of the symbol names. This behaviour means that the use ofRemoveCupsRewriter
would lead to circuits that are outright different to those without the use of the rewriter. This should be undesirable as the role ofRemoveCupsRewriter
should be merely to improve computational efficiency, while keeping outputs untouched.The proposed fix
In the
_ar
method of the base classCircuitAnsat
, a check is added to see if the box is daggered. If so, the un-daggered box is passed to the ansatz whose output would be then daggered.