MrMustard icon indicating copy to clipboard operation
MrMustard copied to clipboard

Faster expectation values

Open JacobHast opened this issue 5 months ago • 3 comments

Before posting a feature request

  • [X] I have searched exisisting GitHub issues to make sure the feature request does not already exist.

Feature details

When calculating displacement-operator expectation-values of pure states in the Fock representation, the current implementation is ~10x slower than extracting the vectors and matrices of the state and operator and multiplying them together manually. So it seems something is limiting the speed of the current implementation.

Implementation

If the current method cannot be sped up, one could use bare matrix multiplication:

def expectation_matmul(state: mm.State, operator: mm.Operation) -> complex:
    state_fock = state.fock(settings.AUTOSHAPE_MAX)
    operator_fock = operator.fock(settings.AUTOSHAPE_MAX)
    return state_fock.T.conj() @ operator_fock @ state_fock

image

How important would you say this feature is?

2: Somewhat important. Needed this quarter.

Additional information

No response

JacobHast avatar Sep 13 '24 10:09 JacobHast