Easy interface for getting the matrix form of a PauliTerm/Sum
In PR #867, @jlbosse is looking to extend the PauliTerm/PauliSum interface to include a method for getting its matrix representation. In the unitary_tools module, there exists a function lifted_pauli which seems to accomplish this task, but is not necessarily well-known or well-documented functionality. This issue is for discussing that feature request, and for designing such an interface.
Some more explanations for the use cases I had in mind:
-
Finding eigenvalues and eigenvectors of (small) enough PauliSums. This is interesting for example for applications in QAOA or VQE.
-
Calculating expectation values and variances via
<wf|pauli_sum|wf>and<wf|pauli_sum**2|wf> - <wf|pauli_sum|wf>**2. This means, that the matrix form should be tensored up in the same order the wavefunction returned by theWavefunctionSimulatoris. Nothe that the expectation value can also be calculated viaWavefunctionSimulator.expectation(), but the variance can't. (well it could, but you would need to run the circuit twice)
+1 to this issue. Would be useful to have this functionality easily accessible.