Qualtran
Qualtran copied to clipboard
Some Bloqs will not serialize.
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:
-
Attempts to decompose bloq using bloq.decompose_bloq()
-
AND does not have this method implemented causing the decomposition to fallback on decompose_from_cirq_style_method().
-
This leads to it iterating through each of the individual operations.
-
One of these operations is both classically controlled and is not a gate which causes _extract_bloq_from_op to raise the error.
Please assign me to this issue as I am currently working on a fix.
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)]