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

Fix tutorial_pulse_programming101.py to type cast expval #1317

Merged
merged 4 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demonstrations/tutorial_pulse_programming101.metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
}
],
"dateOfPublication": "2023-03-08T00:00:00+00:00",
"dateOfLastModification": "2024-10-07T00:00:00+00:00",
"dateOfLastModification": "2025-02-14T00:00:00+00:00",
"categories": [
"Quantum Hardware",
"Quantum Computing"
Expand Down
14 changes: 10 additions & 4 deletions demonstrations/tutorial_pulse_programming101.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,17 @@ def wrapped(p, t):

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

@qml.qnode(dev, interface="jax")

def qnode(theta, t=duration):
qml.BasisState(jnp.array(data.tapered_hf_state), wires=H_obj.wires)
qml.evolve(H_pulse)(params=(*theta, *theta), t=t)
return qml.expval(H_obj)

@qml.qnode(dev)
def _qnode_inner(theta, t=duration):
qml.BasisState(jnp.array(data.tapered_hf_state), wires=H_obj.wires)
qml.evolve(H_pulse)(params=(*theta, *theta), t=t)
return qml.expval(H_obj)

expectation_value = _qnode_inner(theta, t) # Execute the qnode
return jnp.real(expectation_value) # Extract real part


value_and_grad = jax.jit(jax.value_and_grad(qnode))
Expand Down