-
Notifications
You must be signed in to change notification settings - Fork 48
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
Incompatibility of OpType.PhasedX
Gate with GreedyPauliSimp
Optimization
#1771
Comments
Running this code shows it visually: import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
def split_real_imag(matrix):
return matrix.real, matrix.imag
real_start, imag_start = split_real_imag(op_start.data)
real_optimized, imag_optimized = split_real_imag(op_optimized.data)
def zoom_in_matrix(matrix, perc_zoom):
n = matrix.shape[0]
zoom = int(n * perc_zoom)
return matrix[n//2 - zoom:n//2 + zoom, n//2 - zoom:n//2 + zoom]
ZOOM = 0.18
print("Warning: zooming in the matrix by a factor of", ZOOM)
real_start = zoom_in_matrix(real_start, ZOOM)
imag_start = zoom_in_matrix(imag_start, ZOOM)
real_optimized = zoom_in_matrix(real_optimized, ZOOM)
imag_optimized = zoom_in_matrix(imag_optimized, ZOOM)
def plot_combined_heatmaps(real_matrix, imag_matrix, filename):
combined_matrix = np.hstack((real_matrix, imag_matrix))
fig, ax = plt.subplots(figsize=(12, 6))
vmin, vmax = -1, 1
# Create a mask to apply different color maps
mask = np.zeros_like(combined_matrix, dtype=bool)
mask[:, :real_matrix.shape[1]] = True # Left half (real part)
# Plot the heatmap with different color maps
sns.heatmap(combined_matrix, annot=False, fmt=".2f", cmap='Reds',
cbar=False, ax=ax, vmin=vmin, vmax=vmax, mask=~mask)
sns.heatmap(combined_matrix, annot=False, fmt=".2f", cmap='Blues',
cbar=False, ax=ax, vmin=vmin, vmax=vmax, mask=mask)
# Add titles
ax.text(0.25, 1.05, 'Re', ha='center', va='center',
transform=ax.transAxes, fontsize=16)
ax.text(0.75, 1.05, 'Im', ha='center',
va='center', transform=ax.transAxes, fontsize=16)
# Remove ticks
ax.set_xticks([])
ax.set_yticks([])
plt.savefig(filename, bbox_inches='tight')
plt.show()
plot_combined_heatmaps(real_start, imag_start, "PT_1771_unitary_before.png")
plot_combined_heatmaps(real_optimized, imag_optimized,
"PT_1771_unitary_after.png") BEFOREAFTER |
This is probably because |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Expected behavior
Running the AutoRebase including the
OpType.PhasedX
followed by the optimization passGreedyPauliSimp
should lead to a circuit that is equivalent to the original one.Actual behavior
The resulting circuit is not equivalent to the original one when the
OpType.PhasedX
gate is included in the AutoRebase.Additional information
If the
OpType.PhasedX
gate is removed from the circuit, the optimization passGreedyPauliSimp
is able to simplify the circuit leading to an equivalent one. Similarly, if we remove the optimization and run another rebase that does not include theOpType.PhasedX
gate, the resulting circuit is equivalent to the original one. This suggests that the issue is related to the interaction between theOpType.PhasedX
gate and theGreedyPauliSimp
optimization pass.Source code
Run this code to reproduce the issue:
I also double checked with the
mqt.qcec
tool and the circuits are not equivalent.Tracebacks
No crash is observed.
Let me know if you need any further information. Thanks!
The text was updated successfully, but these errors were encountered: