Skip to content

Commit 6332645

Browse files
chore: removed uniform_axes parameter in the plotting function
1 parent 7364c35 commit 6332645

File tree

1 file changed

+28
-41
lines changed

1 file changed

+28
-41
lines changed

tutorials-v5/optimal-control/control-grape-cnot.md

+28-41
Original file line numberDiff line numberDiff line change
@@ -130,49 +130,36 @@ print(np.shape(result.final_amps))
130130
## Plot control fields for cnot gate in the presense of single-qubit tunnelling
131131

132132
```python
133-
def plot_control_amplitudes(times, final_amps, labels, uniform_axes=True):
133+
def plot_control_amplitudes(times, final_amps, labels):
134134
num_controls = final_amps.shape[1]
135135

136-
if uniform_axes:
137-
y_max = 0.1 # Fixed y-axis scale
138-
y_min = -0.1
139-
140-
for i in range(num_controls):
141-
fig, ax = plt.subplots(figsize=(8, 3))
142-
143-
for j in range(num_controls):
144-
# Highlight the current control
145-
color = "black" if i == j else "gray"
146-
alpha = 1.0 if i == j else 0.5
147-
ax.plot(
148-
times,
149-
final_amps[:, j],
150-
label=labels[j],
151-
color=color,
152-
alpha=alpha
153-
)
154-
ax.set_title(f"Control Fields Highlighting: {labels[i]}")
155-
ax.set_xlabel("Time")
156-
ax.set_ylabel(labels[i])
157-
ax.set_ylim(y_min, y_max) # Set fixed y-axis limits
158-
ax.grid(True)
159-
ax.legend()
160-
plt.tight_layout()
161-
plt.show()
162-
else:
163-
for i in range(num_controls):
164-
fig, ax = plt.subplots(figsize=(8, 3))
165-
ax.plot(times, final_amps[:, i], label=labels[i])
166-
ax.set_title(f"Control Field: {labels[i]}")
167-
ax.set_xlabel("Time")
168-
ax.set_ylabel(labels[i])
169-
ax.grid(True)
170-
ax.legend()
171-
plt.tight_layout()
172-
plt.show()
173-
174-
175-
plot_control_amplitudes(times, result.final_amps / (2 * np.pi), H_labels, True)
136+
y_max = 0.1 # Fixed y-axis scale
137+
y_min = -0.1
138+
139+
for i in range(num_controls):
140+
fig, ax = plt.subplots(figsize=(8, 3))
141+
142+
for j in range(num_controls):
143+
# Highlight the current control
144+
color = "black" if i == j else "gray"
145+
alpha = 1.0 if i == j else 0.1
146+
ax.plot(
147+
times,
148+
final_amps[:, j],
149+
label=labels[j],
150+
color=color,
151+
alpha=alpha
152+
)
153+
ax.set_title(f"Control Fields Highlighting: {labels[i]}")
154+
ax.set_xlabel("Time")
155+
ax.set_ylabel(labels[i])
156+
ax.set_ylim(y_min, y_max) # Set fixed y-axis limits
157+
ax.grid(True)
158+
ax.legend()
159+
plt.tight_layout()
160+
plt.show()
161+
162+
plot_control_amplitudes(times, result.final_amps / (2 * np.pi), H_labels)
176163
```
177164

178165
## Fidelity/overlap

0 commit comments

Comments
 (0)