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

[BUG] BasisEmbedding gives the wrong decomposition #6007

Closed
1 task done
isaacdevlugt opened this issue Jul 17, 2024 · 1 comment
Closed
1 task done

[BUG] BasisEmbedding gives the wrong decomposition #6007

isaacdevlugt opened this issue Jul 17, 2024 · 1 comment
Labels
bug 🐛 Something isn't working

Comments

@isaacdevlugt
Copy link
Contributor

Expected behavior

BasisEmbedding's decomp should match BasisStatePreparation.

Actual behavior

It provides the wrong decomp.

Additional information

No response

Source code

import pennylane as qml
from pennylane import numpy as np

n = np.array([0, 1, 1])
wires = [0, 1, 2]

basis_state_prep = qml.BasisStatePreparation.compute_decomposition(n, wires)
basis_embed = qml.BasisEmbedding.compute_decomposition(n, wires)

print(basis_state_prep) # [X(1), X(2)]
print(basis_embed) # [X(1)]

Tracebacks

No response

System information

Name: PennyLane
Version: 0.37.0
Summary: PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Train a quantum computer the same way as a neural network.
Home-page: https://github.com/PennyLaneAI/pennylane
Author: 
Author-email: 
License: Apache License 2.0
Location: /Users/isaac/.virtualenvs/pennylane-catalyst/lib/python3.11/site-packages
Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, packaging, pennylane-lightning, requests, rustworkx, scipy, semantic-version, toml, typing-extensions
Required-by: PennyLane-Catalyst, PennyLane_Lightning

Platform info:           macOS-14.5-arm64-arm-64bit
Python version:          3.11.8
Numpy version:           1.26.4
Scipy version:           1.12.0
Installed devices:
- default.clifford (PennyLane-0.38.0.dev0)
- default.gaussian (PennyLane-0.38.0.dev0)
- default.mixed (PennyLane-0.38.0.dev0)
- default.qubit (PennyLane-0.38.0.dev0)
- default.qubit.autograd (PennyLane-0.38.0.dev0)
- default.qubit.jax (PennyLane-0.38.0.dev0)
- default.qubit.legacy (PennyLane-0.38.0.dev0)
- default.qubit.tf (PennyLane-0.38.0.dev0)
- default.qubit.torch (PennyLane-0.38.0.dev0)
- default.qutrit (PennyLane-0.38.0.dev0)
- default.qutrit.mixed (PennyLane-0.38.0.dev0)
- default.tensor (PennyLane-0.38.0.dev0)
- null.qubit (PennyLane-0.38.0.dev0)
- lightning.qubit (PennyLane_Lightning-0.37.0)
- nvidia.custatevec (PennyLane-Catalyst-0.7.0)
- nvidia.cutensornet (PennyLane-Catalyst-0.7.0)
- oqc.cloud (PennyLane-Catalyst-0.7.0)
- softwareq.qpp (PennyLane-Catalyst-0.7.0)

Existing GitHub issues

  • I have searched existing GitHub issues to make sure the issue does not already exist.
@isaacdevlugt isaacdevlugt added the bug 🐛 Something isn't working label Jul 17, 2024
KetpuntoG added a commit that referenced this issue Aug 21, 2024
This PR complete part of this story:
[[sc-68521](https://app.shortcut.com/xanaduai/story/68521)]

Goal: `BasisEmbedding` is an alias of `BasisState`. This way, we don't
have duplicate code that does the same thing.
In unifying this, I have had to modify some tests due to:
- `BasisEmbedding` and `BasisState` throw errors such as "incorrect
length" with different messages. Now it will always be the same. (test
modified for this reason: `test_default_qubit_legacy.py`,
`test_default_qubit_tf.py`
`test_default_qubit_torch.py`, `test_state_prep.py`,
`test_all_singles_doubles.py` and test_uccsd`)

- In `BasisEmbedding`, errors were thrown in `__init__` while in
BasisState in `state_vector`. Now they are unified in `__init__`. For
this reason, there were tests where the operator was not initialized
correctly but no error was thrown since `state_vector` was not being
called but now they are detected. To correct this, I have modified the
tests: `test_qscript.py`, `test_state_prep.py`,

- Now `BasisState` does not decompose `BasisStatePreparation` since we
are going to deprecate it. This causes the number of gates after
expanding to be affected. In this case I had to modify some test in
`test_tape.py`.

This PR also solves:

- [issue 6008](#6008)
- [issue 6007](#6007)
- [issue 6006](#6006)

---------

Co-authored-by: Isaac De Vlugt <[email protected]>
Co-authored-by: soranjh <[email protected]>
Co-authored-by: Utkarsh <[email protected]>
@DSGuala
Copy link
Contributor

DSGuala commented Sep 6, 2024

Closing as this was resolved in #6021

@DSGuala DSGuala closed this as completed Sep 6, 2024
mudit2812 pushed a commit that referenced this issue Sep 10, 2024
This PR complete part of this story:
[[sc-68521](https://app.shortcut.com/xanaduai/story/68521)]

Goal: `BasisEmbedding` is an alias of `BasisState`. This way, we don't
have duplicate code that does the same thing.
In unifying this, I have had to modify some tests due to:
- `BasisEmbedding` and `BasisState` throw errors such as "incorrect
length" with different messages. Now it will always be the same. (test
modified for this reason: `test_default_qubit_legacy.py`,
`test_default_qubit_tf.py`
`test_default_qubit_torch.py`, `test_state_prep.py`,
`test_all_singles_doubles.py` and test_uccsd`)

- In `BasisEmbedding`, errors were thrown in `__init__` while in
BasisState in `state_vector`. Now they are unified in `__init__`. For
this reason, there were tests where the operator was not initialized
correctly but no error was thrown since `state_vector` was not being
called but now they are detected. To correct this, I have modified the
tests: `test_qscript.py`, `test_state_prep.py`,

- Now `BasisState` does not decompose `BasisStatePreparation` since we
are going to deprecate it. This causes the number of gates after
expanding to be affected. In this case I had to modify some test in
`test_tape.py`.

This PR also solves:

- [issue 6008](#6008)
- [issue 6007](#6007)
- [issue 6006](#6006)

---------

Co-authored-by: Isaac De Vlugt <[email protected]>
Co-authored-by: soranjh <[email protected]>
Co-authored-by: Utkarsh <[email protected]>
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

2 participants