Reading the unitary of a circuit

Is there a way to read the unitary matrix of a quantum circuit in ProjectQ? A similar question was asked for the case of PennyLane without any plugins here, but I was wondering if there’s functionality for this or a more straight forward approach using the ProjectQ plug-in?

Hi @ryanhill1,

No, unfortunately, there isn’t any further convenience features in PennyLane or PennyLane-PQ for this purpose other than those that were suggested in the other thread. However, it is good to note that this would be useful to have!

The way to reproduce the unitary could be to:

  1. Use the @qml.template decorator for a quantum function:
@qml.template
def template():
    qml.CNOT(wires=[0,1])

Using this decorator, calling ops = template() will return the operations defined by template,
2. Iterate through each operation and obtain the matrix representation by querying the matrix property
3. Expand the effect of the operation to the entire subsystem,
4. Multiply each unitary to get the final unitary representation of the circuit.

Note that step 3. can be omitted if the matrices are considered as tensors and we use tensor contractions instead of matrix multiplications in step 4.

Let us know if this would be a preferable way and could help with the steps in more details! :slight_smile:

That makes sense, thank you!