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] Incorrect order of adjoint operations in HilbertSchmidt template #6586

Open
1 task done
justinpickering opened this issue Nov 14, 2024 · 0 comments
Open
1 task done
Labels
bug 🐛 Something isn't working

Comments

@justinpickering
Copy link
Contributor

Expected behavior

  • The adjoint operations should be applied in reverse order.
  • The quantum circuit should be executed correctly with the adjoints applied in the expected order.

In the current implementation of the HilbertSchmidt template, the adjoint of the operations in the function v_function is applied using the following code:

decomp_ops.extend(qml.adjoint(op_v, lazy=False) for op_v in v_tape.operations)

However, this might not be correct as the adjoint should be applied in reverse order. This was noticed in the following test case:

with qml.QueuingManager.stop_recording():
    u_tape = qml.tape.QuantumTape([qml.Hadamard(0)])

def v_function(params):
    qml.RZ(params[0], wires=1)
    qml.RX(params[0], wires=1)

dev = qml.device("default.qubit", wires=2)

@qml.qnode(dev)
def hilbert_test(v_params, v_function, v_wires, u_tape):
    qml.HilbertSchmidt(v_params, v_function=v_function, v_wires=v_wires, u_tape=u_tape)
    return qml.probs(u_tape.wires + v_wires)

print(qml.draw(hilbert_test, level="device")([3*np.pi/2, 3*np.pi/2, np.pi/2], v_function = v_function, v_wires = [1], u_tape = u_tape))

The output shows that since v_function involves RZ followed by RX, the adjoint should likely be applied in the opposite order. The fix would involve changing the line to:

decomp_ops.extend(qml.adjoint(op_v, lazy=False) for op_v in reversed(v_tape.operations))

Actual behavior

The adjoint operations are applied in the incorrect order, which may result in incorrect behavior for certain quantum circuits.

Additional information

No response

Source code

with qml.QueuingManager.stop_recording():
    u_tape = qml.tape.QuantumTape([qml.Hadamard(0)])

def v_function(params):
    qml.RZ(params[0], wires=1)
    qml.RX(params[0], wires=1)

dev = qml.device("default.qubit", wires=2)

@qml.qnode(dev)
def hilbert_test(v_params, v_function, v_wires, u_tape):
    qml.HilbertSchmidt(v_params, v_function=v_function, v_wires=v_wires, u_tape=u_tape)
    return qml.probs(u_tape.wires + v_wires)

print(qml.draw(hilbert_test, level="device")([3*np.pi/2, 3*np.pi/2, np.pi/2], v_function = v_function, v_wires = [1], u_tape = u_tape))

Tracebacks

No response

System information

Name: PennyLane
Version: 0.39.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: /usr/local/lib/python3.10/dist-packages
Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, packaging, pennylane-lightning, requests, rustworkx, scipy, toml, typing-extensions
Required-by: PennyLane_Lightning

Platform info:           Linux-6.1.85+-x86_64-with-glibc2.35
Python version:          3.10.12
Numpy version:           1.26.4
Scipy version:           1.13.1
Installed devices:
- lightning.qubit (PennyLane_Lightning-0.39.0)
- 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)

Existing GitHub issues

  • I have searched existing GitHub issues to make sure the issue does not already exist.
@justinpickering justinpickering added the bug 🐛 Something isn't working label Nov 14, 2024
@justinpickering justinpickering changed the title [BUG] Incorrect order of adjoint operations in HilbertSchmidt template [BUG] Incorrect order of adjoint operations in HilbertSchmidt template Nov 14, 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

1 participant