CQCL / pytket-cutensornet

cuTensorNet Python API extensions for pytket quantum SDK
Apache License 2.0
8 stars 1 forks source link

TensorNetwork converter fails if the circuit has classical registers #44

Open PabloAndresCQ opened 7 months ago

PabloAndresCQ commented 7 months ago

If the pytket.Circuit has any classical register, when calling TensorNetwork on it, we get the following error:

Traceback (most recent call last):
  File "/home/aborgna/src/check-circ-eq/check_eq.py", line 112, in <module>
    run(MAX_QUBITS, results)
  File "/home/aborgna/src/check-circ-eq/check_eq.py", line 75, in run
    is_eq = test_equivalence(new_circ, old_circ)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/aborgna/src/check-circ-eq/check_eq.py", line 30, in test_equivalence
    ket_net = TensorNetwork(ket_circ)
              ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/aborgna/src/check-circ-eq/venv/lib/python3.11/site-packages/pytket/extensions/cutensornet/tensor_network_convert.py", line 87, in __init__
    self._output_index_to_qubit = {
                                  ^
  File "/home/aborgna/src/check-circ-eq/venv/lib/python3.11/site-packages/pytket/extensions/cutensornet/tensor_network_convert.py", line 88, in <dictcomp>
    oi: qname_to_q[qname] for oi, qname in self._graph.output_names.items()
        ~~~~~~~~~~^^^^^^^
KeyError: 'c[0]'

This error occurs even if there are no operations acting on the classical registers. The issue seems to be that self._graph.output_names includes all wires, not only quantum ones.


This issue was found by Agustin Borgna.

PabloAndresCQ commented 7 months ago

My suggestion is that we check for classical registers at the beginning of the conversion and, if we find any, raise a UserError with a message saying something like "Classical registers are not supported. Please remove all classical registers from your circuit."

erinaldiq commented 6 months ago

Oh, I also got the same error, and I was not sure what to do. Is the solution for this to simply remove all classical registers?