CQCL / pytket-cutensornet

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

TensorNetwork converter fails on some random all-to-all connected circuits #88

Closed erinaldiq closed 3 months ago

erinaldiq commented 3 months ago

I get this error after calling TensorNetwork(circuit) using cuQuantum 23.10 and pytket-cutensornet 0.5.2

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
Cell In[34], line 2
      1 # Set the operand data (same on all processes).
----> 2 ket = TensorNetwork(circuit)
      3 ovl = ket.vdot(ket)
      4 if rank == root: print(f"Contracting {int(len(ovl)/2)} tensors.")

File ~/.conda/envs/py-cuquantum-23.10.0-mypich-py3.11/lib/python3.11/site-packages/pytket/extensions/cutensornet/tensor_network_convert.py:68, in TensorNetwork.__init__(self, circuit, adj, loglevel)
     63 self._logger.debug(
     64     f"NX output index to (possibly re-labeled) qubit objects map: "
     65     f"{self._output_index_to_qubit}"
     66 )
     67 self._network = self._graph.as_nx()
---> 68 self._node_tensors = self._assign_node_tensors(adj=adj)
     69 self._node_tensor_indices, self.sticky_indices = self._get_tn_indices(
     70     self._network, adj=adj
     71 )
     72 self._cuquantum_interleaved = self._make_interleaved()

File ~/.conda/envs/py-cuquantum-23.10.0-mypich-py3.11/lib/python3.11/site-packages/pytket/extensions/cutensornet/tensor_network_convert.py:211, in TensorNetwork._assign_node_tensors(self, adj)
    209             self._logger.debug(f"Adding a downward gate tensor")
    210     else:
--> 211         node_tensors.append(self._gate_tensors[node[1]["desc"]][0])
    212         self._logger.debug(f"Adding a 1-qubit gate tensor")
    213 else:

IndexError: list index out of range

circuit is saved in the json file issue_circuit.json and it has

Counter({<OpType.PhasedX: 68>: 416,
         <OpType.Rz: 36>: 288,
         <OpType.ZZPhase: 73>: 128})

There are not measurements and no classical wires. If I rebase to the gateset {X,RZ,CX} I get the same error:

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
Cell In[18], line 2
      1 # Set the operand data (same on all processes).
----> 2 ket = TensorNetwork(circuit)
      3 ovl = ket.vdot(ket)
      4 if rank == root: print(f"Contracting {int(len(ovl)/2)} tensors.")

File ~/.conda/envs/py-cuquantum-23.10.0-mypich-py3.11/lib/python3.11/site-packages/pytket/extensions/cutensornet/tensor_network_convert.py:68, in TensorNetwork.__init__(self, circuit, adj, loglevel)
     63 self._logger.debug(
     64     f"NX output index to (possibly re-labeled) qubit objects map: "
     65     f"{self._output_index_to_qubit}"
     66 )
     67 self._network = self._graph.as_nx()
---> 68 self._node_tensors = self._assign_node_tensors(adj=adj)
     69 self._node_tensor_indices, self.sticky_indices = self._get_tn_indices(
     70     self._network, adj=adj
     71 )
     72 self._cuquantum_interleaved = self._make_interleaved()

File ~/.conda/envs/py-cuquantum-23.10.0-mypich-py3.11/lib/python3.11/site-packages/pytket/extensions/cutensornet/tensor_network_convert.py:211, in TensorNetwork._assign_node_tensors(self, adj)
    209             self._logger.debug(f"Adding a downward gate tensor")
    210     else:
--> 211         node_tensors.append(self._gate_tensors[node[1]["desc"]][0])
    212         self._logger.debug(f"Adding a 1-qubit gate tensor")
    213 else:

IndexError: list index out of range
erinaldiq commented 3 months ago

Same error with the updated version of pytket-cutensornet = v0.5.4

PabloAndresCQ commented 3 months ago

Fixed by #90. @erinaldiq are you able to use pytket-cutensornet installed from a local repo? So that you can use the fix without need for an immediate release.

erinaldiq commented 3 months ago

I do not need a release. Let me try if it gets installed properly on Perlmutter.

PabloAndresCQ commented 3 months ago

Closing now that the bugfix #90 is merged in develop. Thanks for reporting this!