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

Update demos to use new opmath #1067

Merged
merged 27 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
cd2317f
Remove explicit Tensor instances
Qottmann Apr 9, 2024
8004455
remove explicit enable_new_opmath
Qottmann Apr 9, 2024
9510fe8
remove explicit disable_new_opmath
Qottmann Apr 9, 2024
69d7efc
Merge branch 'dev' into newopmath
Qottmann Apr 11, 2024
6313d0b
fix optimal control demo
Qottmann Apr 11, 2024
c6a57dd
merge
Qottmann Apr 11, 2024
e922a63
bugfix optimal control plotting
Qottmann Apr 11, 2024
cd43b8d
remove occurences of .coeffs
Qottmann Apr 11, 2024
acb3208
remove occurences of .ops
Qottmann Apr 11, 2024
331955e
fix barren_gadgets
Qottmann Apr 11, 2024
243e525
typo
Qottmann Apr 11, 2024
7ef470e
typo
Qottmann Apr 11, 2024
59b1a78
fix tutorial_classical_shadows
Qottmann Apr 11, 2024
4703b9d
Merge branch 'dev' of https://github.com/PennyLaneAI/qml into newopmath
Qottmann Apr 12, 2024
931aedd
Blocked by bug that new opmath instances cannot be differentiated in …
Qottmann Apr 12, 2024
c299ae2
Merge branch 'dev' of https://github.com/PennyLaneAI/qml into newopmath
Qottmann Apr 16, 2024
140343d
simplify and fix susceptibility demo
Qottmann Apr 16, 2024
b3815a1
fix resource_estimation
Qottmann Apr 16, 2024
1355d0e
retrigger after qulacs update
Qottmann Apr 16, 2024
0f4bf9f
remove identity without wires while this is not working and fixed on …
Qottmann Apr 17, 2024
1fd003d
trigger
Qottmann Apr 19, 2024
eae6382
Merge branch 'dev' into newopmath
Qottmann Apr 19, 2024
b18d269
remove the removal of the Identity term but use a hamiltonian expand …
Qottmann Apr 23, 2024
3514dd7
fix diffable shadows
Qottmann Apr 23, 2024
023b672
bug fix of the bug fix in diffable shadows
Qottmann Apr 23, 2024
d1edcef
remove hamiltonian expand as it becomes unnecessary :)
Qottmann Apr 25, 2024
f5fea63
remove hamiltonian expand in tapering demo as well
Qottmann Apr 25, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def gadgetize(self, Hamiltonian, target_locality=3):
# Generating the perturbative part
for anc_q in range(ancillary_register_size):
term = qml.PauliX(previous_total+anc_q) @ qml.PauliX(previous_total+(anc_q+1)%ancillary_register_size)
term = qml.operation.Tensor(term, *string.non_identity_obs[
term = qml.prod(term, *string.non_identity_obs[
(target_locality-2)*anc_q:(target_locality-2)*(anc_q+1)])
obs_pert.append(term)
coeffs_pert += [l * sign_correction * Hamiltonian.coeffs[str_count]] \
Expand Down
2 changes: 1 addition & 1 deletion demonstrations/barren_gadgets/barren_gadgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def gadgetize(self, Hamiltonian, target_locality=3):
# Generating the perturbative part
for anc_q in range(ancillary_register_size):
term = qml.PauliX(previous_total+anc_q) @ qml.PauliX(previous_total+(anc_q+1)%ancillary_register_size)
term = qml.operation.Tensor(term, *string.non_identity_obs[
term = qml.prod(term, *string.non_identity_obs[
(target_locality-2)*anc_q:(target_locality-2)*(anc_q+1)])
obs_pert.append(term)
coeffs_pert += [l * sign_correction * Hamiltonian.coeffs[str_count]] \
Expand Down
2 changes: 1 addition & 1 deletion demonstrations/braket-parallel-gradients.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def circuit(params):

# Measure all qubits to make sure all's good with Braket
observables = [qml.PauliZ(n_wires - 1)] + [qml.Identity(i) for i in range(n_wires - 1)]
return qml.expval(qml.operation.Tensor(*observables))
return qml.expval(qml.prod(*observables))


##############################################################################
Expand Down
1 change: 0 additions & 1 deletion demonstrations/tutorial_kernel_based_training.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@

import pennylane as qml
from pennylane.templates import AngleEmbedding, StronglyEntanglingLayers
from pennylane.operation import Tensor

import matplotlib.pyplot as plt

Expand Down
3 changes: 0 additions & 3 deletions demonstrations/tutorial_liealgebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@
import numpy as np
import pennylane as qml
from pennylane import X, Y, Z
qml.operation.enable_new_opmath()

su2 = [1j * X(0), 1j * Y(0), 1j * Z(0)]

Expand Down Expand Up @@ -338,8 +337,6 @@
print(qml.commutator(SZ, SX) == (2j*SY).simplify())
print(qml.commutator(SY, SZ) == (2j*SX).simplify())

qml.operation.disable_new_opmath()

##############################################################################
#
# Another perspective on the inherent :math:`SU(2)` symmetry of :math:`H_\text{Heis}` is that the expectation
Expand Down
4 changes: 2 additions & 2 deletions demonstrations/tutorial_measurement_optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,8 +572,8 @@ def circuit(weights):
def format_pauli_word(term):
"""Convenience function that nicely formats a PennyLane
tensor observable as a Pauli word"""
if isinstance(term, qml.operation.Tensor):
return " ".join([format_pauli_word(t) for t in term.obs])
if isinstance(term, qml.ops.Prod):
return " ".join([format_pauli_word(t) for t in term])

return f"{term.name[-1]}{term.wires.tolist()[0]}"

Expand Down
16 changes: 4 additions & 12 deletions demonstrations/tutorial_optimal_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,6 @@ def run_adam(profit_fn, grad_fn, params, learning_rate, num_steps):
colors = {0: "#70CEFF", 1: "#C756B2", 2: "#FDC357"}
dashes = {"X": [10, 0], "Y": [2, 2, 10, 2], "Z": [6, 2]}


def plot_optimal_pulses(hist, pulse_fn, ops, T, target_name):
_, profit_hist = list(zip(*hist))
fig, axs = plt.subplots(2, 1, figsize=(10, 9), gridspec_kw={"hspace": 0.0}, sharex=True)
Expand All @@ -574,18 +573,11 @@ def plot_optimal_pulses(hist, pulse_fn, ops, T, target_name):
max_params, max_profit = hist[jnp.argmax(jnp.array(profit_hist))]
plot_times = jnp.linspace(0, T, 300)
# Iterate over pulse parameters and parametrized operators
for p, op in zip(max_params, ops):
for i, (p, op) in enumerate(zip(max_params, ops)):
# Create label, and pick correct axis
label = op.name
ax = axs[0] if isinstance(label, str) else axs[1]
# Convert the label into a concise string. This differs depending on
# whether the operator has a single or multiple Pauli terms. Pick the line style
if isinstance(label, str):
label = f"${label[-1]}_{op.wires[0]}$"
dash = dashes[label[1]]
else:
label = "$" + " ".join([f"{n[-1]}_{w}" for w, n in zip(op.wires, label)]) + "$"
dash = [10, 0]
label = str(op)
dash = dashes[label[0]]
ax = axs[0] if len(op.wires) == 1 else axs[1]

# Set color according to qubit the term acts on
col = colors[op.wires[0]]
Expand Down
4 changes: 2 additions & 2 deletions demonstrations/tutorial_toric_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class Wire:

sites = [(x0, y), (x0 + 1, y), (x0 + 1, y + 1), (x0, y + 1)]

op = qml.operation.Tensor(*(qml.PauliZ(mod(s)) for s in sites))
op = qml.prod(*(qml.PauliZ(mod(s)) for s in sites))

zgroup_sites.append(sites)
zgroup_ops.append(op)
Expand All @@ -197,7 +197,7 @@ class Wire:
if x == 2 and y == 1: # change order for state prep later
sites = sites[1:] + sites[0:1]

op = qml.operation.Tensor(*(qml.PauliX(mod(s)) for s in sites))
op = qml.prod(*(qml.PauliX(mod(s)) for s in sites))

xgroup_sites.append(sites)
xgroup_ops.append(op)
Expand Down
Loading