Qualtran icon indicating copy to clipboard operation
Qualtran copied to clipboard

Some Bloqs will not serialize.

Open Epsilon1024 opened this issue 11 months ago • 1 comments

This issue was originally discovered by serializing a composite bloq which contains an AND bloq. The AND bloq fails to serialize and raises this error. It is likely that there are other bloqs which will have similar problems.

A summary of the path to the error is as follows:

The path to the error is as follows:

  1. Attempts to decompose bloq using bloq.decompose_bloq()

  2. AND does not have this method implemented causing the decomposition to fallback on decompose_from_cirq_style_method().

  3. This leads to it iterating through each of the individual operations.

  4. One of these operations is both classically controlled and is not a gate which causes _extract_bloq_from_op to raise the error.

Epsilon1024 avatar Mar 01 '24 01:03 Epsilon1024

Please assign me to this issue as I am currently working on a fix.

Epsilon1024 avatar Mar 01 '24 01:03 Epsilon1024

The serialization code now tries to build a composite bloq; and if a composite bloq doesn't exist / cannot be built (eg: due to classically controlled operations appearing in the decomposition) it gracefully considers the bloq to be a leaf bloq. This issue can now be closed.

In [8]: bloqs_from_proto(bloqs_to_proto(And()))
Out[8]:
[And(cv1=1, cv2=1, uncompute=0),
 Allocate(dtype=QAny(bitsize=1)),
 Hadamard(),
 TGate(is_adjoint=0),
 CNOT(),
 TGate(is_adjoint=1),
 SGate(is_adjoint=0),
 ArbitraryClifford(n=2)]

In [10]: bloqs_from_proto(bloqs_to_proto(And().adjoint()))
Out[10]: [And(cv1=1, cv2=1, uncompute=1), ArbitraryClifford(n=2)]

tanujkhattar avatar Aug 13 '24 03:08 tanujkhattar