quantumlib / Cirq

A Python framework for creating, editing, and invoking Noisy Intermediate Scale Quantum (NISQ) circuits.
Apache License 2.0
4.25k stars 1.01k forks source link

Add sparse_matrix method to PauliSum #3057

Open kevinsung opened 4 years ago

kevinsung commented 4 years ago

There doesn't seem to be an easy way to get the matrix of a PauliSum. It has no matrix method, nor do we have a matrix protocol. Typically one actually wants the matrix as a Scipy sparse matrix rather than a Numpy array. We should make this easy. Should it be a method or a protocol?

kevinsung commented 4 years ago

At Cirq sync we decided to first add a matrix and/or sparse_matrix method to PauliSum, and only consider making these protocols if there are more use cases. The methods added to PauliSum should take qubit_order as argument.

kevinsung commented 4 years ago

OpenFermion has an analogous method but it gets quite slow and memory intensive for large matrices and I suspect it can be implemented more efficiently.