Spaces:
Runtime error
Runtime error
Download src/utils/visualization.py from QuantumGenAI/ErrorMitigation: direct link, hf CLI and curl.
- Browser
- Download file 1.43 kB
-
https://huggingface.co/spaces/QuantumGenAI/ErrorMitigation/resolve/main/src/utils/visualization.py
- Command line
-
hf download hf://spaces/QuantumGenAI/ErrorMitigation/src/utils/visualization.py
-
curl -L -o visualization.py https://huggingface.co/spaces/QuantumGenAI/ErrorMitigation/resolve/main/src/utils/visualization.py
1.43 kB
| import pennylane as qml | |
| import matplotlib.pyplot as plt | |
| def visualize_circuit( | |
| qnode_func, | |
| params, | |
| title="Quantum Circuit Visualization", | |
| fig_bg_color="lightblue", | |
| ax_bg_color="whitesmoke", | |
| text_color="darkblue", | |
| font_size=12, | |
| save_path=None, | |
| ): | |
| """ | |
| Visualize a quantum circuit with customizable styling options. | |
| Args: | |
| qnode_func: The quantum node representing the circuit. | |
| params (array): Parameters to pass to the quantum node. | |
| title (str): Title for the circuit diagram. | |
| fig_bg_color (str): Background color for the figure. | |
| ax_bg_color (str): Background color for the axis. | |
| text_color (str): Color for the text labels. | |
| font_size (int): Font size for the text labels. | |
| save_path (str): File path to save the visualization (optional). | |
| Returns: | |
| None: Displays or saves the circuit visualization. | |
| """ | |
| # Generate the matplotlib figure | |
| fig, ax = qml.draw_mpl(qnode_func)(params) | |
| # Customize the figure | |
| fig.patch.set_facecolor(fig_bg_color) | |
| ax.set_facecolor(ax_bg_color) | |
| # Customize text labels | |
| for text in ax.texts: | |
| text.set_color(text_color) | |
| text.set_fontsize(font_size) | |
| # Add title | |
| ax.set_title(title, color=text_color, fontsize=font_size + 2) | |
| if save_path: | |
| fig.savefig(save_path, dpi=300, bbox_inches="tight") | |
| else: | |
| plt.show() | |