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

Layout of transpiled circuit is not being applied to the operators #611

Open
felipelewyee opened this issue Jan 8, 2025 · 4 comments · May be fixed by #613
Open

Layout of transpiled circuit is not being applied to the operators #611

felipelewyee opened this issue Jan 8, 2025 · 4 comments · May be fixed by #613

Comments

@felipelewyee
Copy link

felipelewyee commented Jan 8, 2025

Describe the bug
The layout of the transpiled circuit is not being applied to the observables, leading to wrong results when it differs from the layout of the original circuit. This can be solved by adding

compiled_observables = [op.apply_layout(compiled_circuits[0].layout) for op in pauli_observables]

as line 657 of "_execute_estimator" in qiskit_device.py, and modifying line 663 to be:

circ_and_obs = [(compiled_circuits[0], compiled_observables)]

To Reproduce
The result of the following minimal circuit should be close to 1, but instead the circuit execution gives close to 0. (I have used optimization_level=2 to allow the layout to change in transpilation. Using optimization_level=0 produce the right result for this circuit as the layout is not changed.)

from qiskit_ibm_runtime.fake_provider import FakeKyoto
backend = FakeKyoto()

dev = qml.device("qiskit.remote", wires=127, backend=backend, optimization_level=2)

@qml.qnode(dev)
def circuit():
    qml.Hadamard(0)
    return qml.expval(qml.PauliX(0))

circuit()

Expected behavior
Layout of transpiled circuit should be applied to the operators.

Screenshots
I have added some prints as reference:
imagen

It can be seen that the layout has changed in transpilation
imagen

The Pauli observable has the layout of the original circuit, while the compiled observable has the correct Layout and gives an expectation value close to 1 (the correct result).
imagen

Version (qml.about()):
Name: PennyLane
Version: 0.39.0
Platform info: Linux-6.11.0-13-generic-x86_64-with-glibc2.40
Python version: 3.10.0
Numpy version: 2.0.2
Scipy version: 1.15.0
Installed devices:

  • default.clifford (PennyLane-0.39.0)
  • default.gaussian (PennyLane-0.39.0)
  • default.mixed (PennyLane-0.39.0)
  • default.qubit (PennyLane-0.39.0)
  • default.qutrit (PennyLane-0.39.0)
  • default.qutrit.mixed (PennyLane-0.39.0)
  • default.tensor (PennyLane-0.39.0)
  • null.qubit (PennyLane-0.39.0)
  • reference.qubit (PennyLane-0.39.0)
  • qiskit.aer (PennyLane-qiskit-0.39.1)
  • qiskit.basicaer (PennyLane-qiskit-0.39.1)
  • qiskit.basicsim (PennyLane-qiskit-0.39.1)
  • qiskit.remote (PennyLane-qiskit-0.39.1)
  • lightning.qubit (PennyLane_Lightning-0.39.0)
@CatalinaAlbornoz
Copy link

Thank you for the very clear description of this bug @felipelewyee !!

I don't know if we'll have the time to fix this before the next release (which will likely be next week) but we'll do our best to fix it very soon and keep you updated.

Thanks again.

@CatalinaAlbornoz
Copy link

Hi @felipelewyee,

Thanks again for reporting this bug. Our team has reviewed it and they liked your suggestion for the fix. Would you like to open a Pull Request (PR) for the fix? Make sure the PR is targeting master. If this is your first PR let us know and we can guide you through the process. On the other hand, if you prefer that we make the PR (instead of opening it yourself) we can do it. Just let us know what you prefer.

@felipelewyee
Copy link
Author

Hi, thanks for checking my report. I am opening the PR in a moment.

@felipelewyee
Copy link
Author

I have done the PR. Let me know if something is needed, and thanks in advance.

@astralcai astralcai linked a pull request Jan 14, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants