Add scalar multiplication `__mul__` method to `SparseHamiltonian`
See original GitHub issueSuppose we create a Sparse Hamiltonian
import pennylane as qml
from scipy import sparse
sparse_mat = sparse.coo_matrix(np.array([[1.0, 2.0], [2.0, 3.0]]))
h = qml.SparseHamiltonian(sparse_mat, wires=[0])
If we multiply this by a float, we get back a Hamiltonian object pairing the SparseHamiltonian with a coefficient:
>>> new_h = -1.0 * h
>>> print(new_h)
(-1.0) [SparseHamiltonian0]
We should instead create a new SparseHamiltonian object with a new matrix. This way we can keep the benefits of having a SparseHamiltonian object.
This would be accomplished by defining the __mul__ and __rmul__ dunder methods in SparseHamiltonian located in pennylane/ops/qubit/observables.py
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:9 (8 by maintainers)
Top Results From Across the Web
A sparse matrix-vector multiplication based algorithm for ...
We present an efficient sparse matrix vector (SpMV) based method to com- pute the density matrix P from a given Hamiltonian in electronic ......
Read more >Exponential improvement in precision for simulating sparse ...
The first efficient algorithm for sparse Hamiltonian simulation was due to Aharonov and Ta- ... and π by adding the identity matrix and...
Read more >The Distributed Block-Compressed Sparse Row Library
way, an autotuning library for small matrix multiplications, ... both the density matrix and the Hamiltonian matrix become sparse but the.
Read more >Source code for quspin.operators.hamiltonian_core
`fun`: function object which multiplies the matrix or operator given in the ... function does the matrix multiplication with the state(s) and Hamiltonian...
Read more >parallel sparse matrix-matrix multiplication and indexing ...
Our novel approach to. SpRef uses SpGEMM as its key subroutine, which regularizes the computation and data access patterns; conversely, applying SpGEMM to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Hi @tgag17, sure 🙂 Feel free to reach out for help/when ready for the PR to be reviewed.
Hi @tgag17, apologies for the late reply. Changes in the
masterbranch have made the original snippet outdated and also seem to have made this issue be resolved (cc @albi3ro):(-1.0) [SparseHamiltonian0]