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:
- 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!
That makes sense, thank you!
Vio era foble cablna blanco
Hey @Jonathan_alexis_Nune, welcome to the forum
English is the preferred / default language on the forum, but we welcome people to speak with each other in whatever language they prefer. Just note that getting help from the PennyLane team will require you to at least put it through Google Translate if we don’t have anyone internal that can speak your preferred language.