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

Number of modes supplied (...) must match the representation dimension ... #293

Closed
1 task done
jan-provaznik opened this issue Oct 19, 2023 · 6 comments
Closed
1 task done
Labels
bug Something isn't working

Comments

@jan-provaznik
Copy link
Contributor

Before posting a bug report

  • 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 #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.
@jan-provaznik jan-provaznik added the bug Something isn't working label Oct 19, 2023
@ziofil
Copy link
Collaborator

ziofil commented Oct 19, 2023

Yikes! Thanks for finding this. @SamFerracin do you think this will be addressed automatically when we use the new Tensor class everywhere?

@jan-provaznik
Copy link
Contributor Author

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 #292, these two properties are not equal.

@SamFerracin
Copy link
Contributor

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 :)

@ziofil
Copy link
Collaborator

ziofil commented Apr 8, 2024

@SamFerracin can we close this or is it still relevant?

@SamFerracin
Copy link
Contributor

@ziofil Fixed in lab_dev, not in lab

@ziofil
Copy link
Collaborator

ziofil commented Nov 5, 2024

fixed in lab_dev

@ziofil ziofil closed this as completed Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants