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] Discrepancy in output values of the example of qml.pulse.drive #6025

Open
1 task done
Shiro-Raven opened this issue Jul 22, 2024 · 1 comment
Open
1 task done
Labels
bug 🐛 Something isn't working

Comments

@Shiro-Raven
Copy link
Contributor

Expected behavior

Output of the code example in the qml.pulse.hardware_hamiltonian.drive function should be consistent with the output from the docs.

Actual behavior

Instead of receiving the docs output:

>>> params = [2.4]
>>> circuit(params)
Array(0.32495208, dtype=float64)
>>> jax.grad(circuit)(params)
[Array(1.31956098, dtype=float64)]

The following is returned:

>>> circuit(params)
Array(-0.17375104, dtype=float64)
>>> jax.grad(circuit)(params)
[Array(13.66916253, dtype=float64, weak_type=True)]

Additional information

No response

Source code

import pennylane as qml
import jax
from jax import numpy as jnp

import jax


jax.config.update("jax_enable_x64", True)
wires = [0, 1, 2, 3]
H_int = sum([qml.X(i) @ qml.X((i + 1) % len(wires)) for i in wires])

amplitude = lambda p, t: p * jnp.sin(jnp.pi * t)
phase = jnp.pi / 2
H_d = qml.pulse.drive(amplitude, phase, wires)


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


@qml.qnode(dev, interface="jax")
def circuit(params):
    qml.evolve(H_int + H_d)(params, t=[0, 10])
    return qml.expval(qml.Z(0))


params = [2.4]
print(circuit(params))
print(jax.grad(circuit)(params))

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/ahmed.darwish/Desktop/Code/xanadu-dev/lib/python3.9/site-packages
Editable project location: /Users/ahmed.darwish/Desktop/Code/pennylane
Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, packaging, pennylane-lightning, requests, rustworkx, scipy, semantic-version, toml, typing-extensions
Required-by: amazon-braket-pennylane-plugin, PennyLane-Catalyst, PennyLane-qiskit, PennyLane_Lightning, PennyLane_Lightning_Kokkos

Platform info:           macOS-14.5-arm64-arm-64bit
Python version:          3.9.19
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)
- nvidia.custatevec (PennyLane-Catalyst-0.7.0.dev0)
- nvidia.cutensornet (PennyLane-Catalyst-0.7.0.dev0)
- oqc.cloud (PennyLane-Catalyst-0.7.0.dev0)
- softwareq.qpp (PennyLane-Catalyst-0.7.0.dev0)
- lightning.qubit (PennyLane-Lightning-0.37.0.dev42)
- lightning.kokkos (PennyLane-Lightning-Kokkos-0.37.0.dev42)
- braket.aws.ahs (amazon-braket-pennylane-plugin-1.28.0)
- braket.aws.qubit (amazon-braket-pennylane-plugin-1.28.0)
- braket.local.ahs (amazon-braket-pennylane-plugin-1.28.0)
- braket.local.qubit (amazon-braket-pennylane-plugin-1.28.0)
- qiskit.aer (PennyLane-qiskit-0.37.0.dev0)
- qiskit.basicaer (PennyLane-qiskit-0.37.0.dev0)
- qiskit.basicsim (PennyLane-qiskit-0.37.0.dev0)
- qiskit.ibmq (PennyLane-qiskit-0.37.0.dev0)
- qiskit.ibmq.circuit_runner (PennyLane-qiskit-0.37.0.dev0)
- qiskit.ibmq.sampler (PennyLane-qiskit-0.37.0.dev0)
- qiskit.remote (PennyLane-qiskit-0.37.0.dev0)

Existing GitHub issues

  • I have searched existing GitHub issues to make sure the issue does not already exist.
@Shiro-Raven Shiro-Raven added the bug 🐛 Something isn't working label Jul 22, 2024
@trbromley
Copy link
Contributor

From discussions, it looks like the code example just doesn't account for a factor of $2 \pi$, so we can just update the docstrings of drive().

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