Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow measuring expectation values specified via eigvals + wires #768

Open
albi3ro opened this issue Jun 18, 2024 · 0 comments
Open

Allow measuring expectation values specified via eigvals + wires #768

albi3ro opened this issue Jun 18, 2024 · 0 comments

Comments

@albi3ro
Copy link
Contributor

albi3ro commented Jun 18, 2024

Pennylane allows specifying measurements like ExpectationMP via a combination of wires + eigenvalues:

ExpectationMP(eigvals=np.array([-1.0, 1.0]), wires=qml.wires.Wires((0,1)))

While not user-facing, this can be produced internally, for example from:

>>> qml.expval(qml.X(0)).expand().circuit
[Hadamard(wires=[0]), expval(eigvals=[ 1. -1.], wires=[0])]

Trying to measure such an observable on lightning gives:

File [pennylane-lightning/pennylane_lightning/lightning_qubit/_measurements.py:145](pennylane-lightning/pennylane_lightning/lightning_qubit/_measurements.py#line=144), in LightningMeasurements.expval(self, measurementprocess)
    134     CSR_SparseHamiltonian = measurementprocess.obs.sparse_matrix(
    135         wire_order=list(range(self._qubit_state.num_wires))
    136     ).tocsr(copy=False)
    137     return self._measurement_lightning.expval(
    138         CSR_SparseHamiltonian.indptr,
    139         CSR_SparseHamiltonian.indices,
    140         CSR_SparseHamiltonian.data,
    141     )
    143 if (
    144     isinstance(measurementprocess.obs, (qml.ops.Hamiltonian, qml.Hermitian))
--> 145     or (measurementprocess.obs.arithmetic_depth > 0)
    146     or isinstance(measurementprocess.obs.name, List)
    147 ):
    148     ob_serialized = QuantumScriptSerializer(
    149         self._qubit_state.device_name, self.dtype == np.complex64
    150     )._ob(measurementprocess.obs)
    151     return self._measurement_lightning.expval(ob_serialized)

AttributeError: 'NoneType' object has no attribute 'arithmetic_depth'

I'm not too concerned about this, as default.qubit seems to not even really support this right now, and there's really no user-facing of creating this, but we should at least track it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant