MrMustard
MrMustard copied to clipboard
Number of modes supplied (...) must match the representation dimension ...
Before posting a bug report
- [X] I have searched exisisting GitHub issues to make sure the issue does not already exist.
Expected behavior
Once expects a projection onto a Fock state to work.
Actual behavior
One is met with
AssertionError: Number of modes supplied (...) must match the representation dimension ...
Reproduces how often
Whenever the bug https://github.com/XanaduAI/MrMustard/issues/292 gets triggered.
System information
...
Source code
fail_state = (
mrmustard.lab.TMSV(r = 0.0115, modes = [ 0, 1 ])
>> mrmustard.lab.Attenuator(transmissivity = 0.96, modes = [ 1 ])
)
fail_state << mrmustard.lab.Fock(1, modes = [ 1 ])
Tracebacks
No response
Additional information
`Fock` implements [_preferred_projection](https://github.com/XanaduAI/MrMustard/blob/develop/mrmustard/lab/states.py#L493) and [_contract_with_other](https://github.com/XanaduAI/MrMustard/blob/develop/mrmustard/lab/abstract/state.py#L424) takes [advantage of it](https://github.com/XanaduAI/MrMustard/blob/develop/mrmustard/lab/abstract/state.py#L429). When performing [_project_onto_fock](https://github.com/XanaduAI/MrMustard/blob/develop/mrmustard/lab/abstract/state.py#L395), the marginal is computed through [_preferred_projection](https://github.com/XanaduAI/MrMustard/blob/develop/mrmustard/lab/states.py#L516), which returns either a vector or a density matrix depending on the value of `other.is_hilbert_vector`. The form of the resulting state [is determined](https://github.com/XanaduAI/MrMustard/blob/develop/mrmustard/lab/abstract/state.py#L412) through `other.is_pure`. As per the referenced bug https://github.com/XanaduAI/MrMustard/issues/292, these two properties are not equal.
Yikes! Thanks for finding this. @SamFerracin do you think this will be addressed automatically when we use the new Tensor
class everywhere?
You're welcome. It is a consequence of the other bug. Sadly the additional information above was interpreted as code block and explains how the bug happens with references to the implementation. Pasted below.
Fock
implements _preferred_projection and _contract_with_other takes advantage of it. When performing _project_onto_fock, the marginal is computed through _preferred_projection, which returns either a vector or a density matrix depending on the value of other.is_hilbert_vector
. The form of the resulting state is determined through other.is_pure
. As per the referenced bug https://github.com/XanaduAI/MrMustard/issues/292, these two properties are not equal.
Thanks, @jan-provaznik!
Yes, I believe that this will be addressed automatically in the next few weeks when we add Tensor
support to states, as we have done for transformations. I will add this example to the list of tests to make sure that it works :)
@SamFerracin can we close this or is it still relevant?
@ziofil Fixed in lab_dev, not in lab