Closed mariaschuld closed 3 years ago
See #1052
See #1052
Ah!
I feel like this is subtly different though, as here we want to compute an expectation of a projector given a state and its gradients, whereas in #1052 the goal is to perform a projection of the quantum state on the device (two slightly different pathways). This is more analagous to qml.FockStateProjector()
, which already exists in PL.
Although the UI might converge, in either case.
Hello! I have just started working on this issue and created a PR#1356. So far I have a brief draft that works for default.qubit, and I will still need to include checks to ensure correct inputs and tests for the Projector observable. Do you have any tips on what tests I should include? I only have input tests in my mind. And can you point some directions on how to implement for other devices, like qiskit?
Thanks @wongwsvincent! Let us know by leaving a comment when it is ready for review 🙂
Regarding supporting multiple devices: one thing that could potentially be done is add support for this new observable directly in the parent QubitDevice
class, in a hardware compatible manner. This way:
All devices that inherit from QubitDevice
will automatically support this new observable in a way that is compatible with hardware. E.g., qml.Projector([0, 1, 0], wires=[0, 2, 3])
would ask the device to return the marginal probability over wires [0, 2, 3]
, and then extract the [0, 1, 0]
element.f
Optionally, this could be overwritten on a device-by-device manner if a more efficient approach exists for a particular device.
Sorry, @josh146 . I am a bit lost with your suggestion about implementing this under the QubitDevice
class.
If I understand you correctly, you are saying we could add a function in pennylane/_qubit_device.py
as a function of the QubitDevice
class, like the functions marginal_prob
. But I thought we were going to implement the Projector
class as an observable class like the Hermitian
class.
In the PR, I have prepared a version of the latter case, which only works for default.qubit
and I believe that's not what you are suggesting.
Could you give me more pointers? Should I create a function under the QubitDevice
class and call it "projected_prob", or is it something else that you meant?
Hi @wongwsvincent, let's move the discussion over to your PR, it will provide me with better context as to the changes you have made. I'll give it a preliminary review 🙂
This issue has been tagged for contributions during unitaryHACK
For some applications it would be elegant and useful to have a PennyLane observable that implements the projector |i >< i| onto the i'th computational basis state. For example, for 3 qubits and i=4, the computational basis state is "[0, 1, 1]" and the observable could be implemented as
Note that the projector acts by default on all qubits.
At the moment one can implement this observable in two work-arounds:
1) Via the
qml.Hermitian
observable2) By making use of the fact that this expectation is the i'th probability in the
probs
return value:Creating this new observable would involve creating the class itself (inheriting from
qml.operations.Observable
), and supporting it by the different devices (for example, indefault.qubit
one can implement it by selecting the right amplitude in the state vector and taking its absolute square; in the qiskit plugin one would have to translate the observable into the correct qiskit operation, etc).