Final Report

gsoc
qutip
report
Author

Rushiraj Gadhvi

Published

August 23, 2024

Project Description

The project aims to improve the quantum circuit visualization capabilities of QuTiP-QIP by introducing a new framework for circuit rendering that doesn’t rely on external dependencies. Presently, circuit visualization relies on LaTeX and ImageMagick, which can be problematic for users. This solution plans to create two rendering modules: one utilizing matplotlib for visually appealing and precise quantum circuit diagrams, and another ASCII text-based rendering. The matplotlib renderer will also support generating circuit visualizations within IPython environments like Jupyter Notebook, while the text-based renderer will cater to command-line interactions. Apart from the rendering modules a Circuit Renderer Selector will also be included in the project deliverables, enabling users to easily choose their preferred rendering method among LaTeX, Matplotlib, or Text-Based options. These tools will enable users to visualize quantum circuits more efficiently and effectively, making it easier to work with QuTiP.

Mentors: Boxi Li, Alex Pitchford, Neill Lambert

Deliverables

Contributions

Weekly Progress Documented Here: Weekly Blogs πŸ”—

The following sections review all the contributions made to the project during the GSoC ’24 coding period.

BaseRenderer

The BaseRenderer was designed as a parent class to improve the maintainability of newly added renderers and to establish a robust framework for incorporating future renderers. By employing a layered approach, it optimizes the compactness of quantum circuits, dynamically adjusting the layout as each gate is added. This method ensures efficient space management and enhances the clarity of complex quantum operations.

Furthermore, the BaseRenderer acts as a central hub for styling configurations through the StyleConfig class. This dataclass consolidates all customization settings, enabling consistent and streamlined styling across different renderers.


Next, we will delve into the details of the two newly added renderers.

MatRenderer

A Matplotlib-based renderer was developed to plot complex quantum circuits, providing numerous customization options so users can adjust their circuits to meet specific needs. The features of the renderer were designed to ensure precise information delivery while maintaining visually appealing diagrams. We also prioritized compactness, arranging the circuit layout to be as optimal while maintaing the information delivery.

Example of Results

QuTiP-QIP default color-theme

Layer Alignment Customization and Argument Display Option

Gate Bulge Customization and MultiQubit Gate Connectors for better Information Delivery

Dark color-theme

Further Details about MatRenderer

The MatRenderer offers four distinct color themes: qutip, dark, light, and modern. Users can personalize these themes further through styling configurations. They can also choose between the modern bulge style and the classic box style for gate appearances. The renderer enhances clarity with connectors for MultiQubit Gates and an option to display arguments.

MatRenderer also provides extensive customization options. Users can adjust wire labeling, background color, font family, font size, and more, creating a highly personalized and visually appealing representation of quantum circuits.


TextRenderer

Nowadays, most users rely on Matplotlib. However, users who interact with libraries through the terminal require a different type of renderer. TextRender is ideal for those using the terminal or for quick circuit checks to ensure the library correctly interprets their intentions. The TextRenderer has fewer customization options compared to the MatRenderers, but it still provides some level of customization.

Example of Results

        β”Œβ”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”   
 q1 :──── CNOT β”œβ”€β”€β”€ SNOT β”œβ”€β”€β”€       β”œβ”€β”€β”€ M β”œβ”€β”€β”€
        β””β”€β”€β”€β”¬β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”˜  β”‚       β”‚  └─β•₯β”€β”˜   
            β”‚               β”‚       β”‚    β•‘     
 q0 :β”€β”€β”€β”€β”€β”€β”€β–ˆβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ ISWAP β”œβ”€β”€β”€β”€β•‘β”€β”€β”€β”€β”€
                            β””β”€β”€β”€β”€β”€β”€β”€β”˜    β•‘     
                                         β•‘     
 c0 :════════════════════════════════════╩═════
                                               

Layer Alignment Customization

        β”Œβ”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”                    
 q2 :──── RZ β”œβ”€β”€β”€ RZ β”œβ”€β”€β”€ RX β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β•³β”€β”€β”€β”€
        β””β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”˜               β”‚    
        β”Œβ”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”   β”‚    
 q1 :──── H β”œβ”€β”€β”€β”€ RX β”œβ”€β”€β”€ CNOT β”œβ”€β”€β”€ CNOT β”œβ”€β”€β”€β”‚β”€β”€β”€β”€
        β””β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”¬β”€β”€β”˜  β””β”€β”€β”€β”¬β”€β”€β”˜   β”‚    
        β”Œβ”€β”€β”€β”€β”              β”‚         β”‚      β”‚    
 q0 :──── RX β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–ˆβ”€β”€β”€β”€β”€β”€β”€β”€β”€β–ˆβ”€β”€β”€β”€β”€β”€β•³β”€β”€β”€β”€
        β””β”€β”€β”€β”€β”˜                                    

Skips drawing a connection line for wires that are not directly involved in a MultiQubit Gate.

                                        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                                         
 q3 :───────────────────────────────╳────          β”œβ”€β”€β”€β”€β”€β”€β”€β–ˆβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β•³β”€β”€β”€β”€β•³β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
                                    β”‚   β”‚          β”‚       β”‚                         β”‚    β”‚                  
        β”Œβ”€β”€β”€β”                       β”‚   β”‚          β”‚  β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”                    β”‚    β”‚                  
 q2 :──── X β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”‚β”€β”€ β”‚          β”‚ ──         β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”‚β”€β”€β”€β”€β”‚β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
        β””β”€β”€β”€β”˜                       β”‚   β”‚          β”‚  β”‚         β”‚                    β”‚    β”‚                  
        β”Œβ”€β”€β”€β”            β”Œβ”€β”€β”€β”€β”€β”€β”   β”‚   β”‚          β”‚  β”‚         β”‚  β”Œβ”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”   β”‚    β”‚          β”Œβ”€β”€β”€β”   
 q1 :──── H β”œβ”€β”€β”€β”€β”€β”€β–ˆβ”€β”€β”€β”€β”€β”€ CNOT β”œβ”€β”€β”€β”‚β”€β”€ β”‚          β”‚ ── FREDKIN β”œβ”€β”€β”€ CX β”œβ”€β”€β”€ CRX β”œβ”€β”€β”€β”‚β”€β”€β”€β”€β”‚β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ M β”œβ”€β”€β”€
        β””β”€β”€β”€β”˜      β”‚     β””β”€β”€β”€β”¬β”€β”€β”˜   β”‚   β”‚          β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”¬β”€β”˜  β””β”€β”€β”¬β”€β”€β”˜   β”‚    β”‚          └─β•₯β”€β”˜   
        β”Œβ”€β”€β”€β”  β”Œβ”€β”€β”€β”΄β”€β”€β”      β”‚      β”‚   β”‚          β”‚                  β”‚       β”‚      β”‚    β”‚   β”Œβ”€β”€β”€β”    β•‘     
 q0 :──── H β”œβ”€β”€β”€ CNOT β”œβ”€β”€β”€β”€β”€β”€β–ˆβ”€β”€β”€β”€β”€β”€β•³β”€β”€β”€β”€ BERKELEY β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–ˆβ”€β”€β”€β”€β”€β”€β”€β–ˆβ”€β”€β”€β”€β”€β”€β•³β”€β”€β”€β”€β•³β”€β”€β”€β”€ M β”œβ”€β”€β”€β”€β•‘β”€β”€β”€β”€β”€
        β””β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”˜                 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                          └─β•₯β”€β”˜    β•‘     
                                                                                                β•‘      β•‘     
 c1 :═══════════════════════════════════════════════════════════════════════════════════════════║══════╩═════
                                                                                                β•‘            
                                                                                                β•‘            
 c0 :═══════════════════════════════════════════════════════════════════════════════════════════╩════════════

Complex Circuit

                                                                                                                    β”Œβ”€β”€β”€β”€β”€β”€β”          β”Œβ”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”          β”Œβ”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”   
 q3 :──────────────────────────────────────────────────────────────────────────────────────────────────────────────── CNOT β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ CNOT β”œβ”€β”€β”€ RZ β”œβ”€β”€β”€ CNOT β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ CNOT β”œβ”€β”€β”€ RZ β”œβ”€β”€β”€
                                                                                                                    β””β”€β”€β”€β”¬β”€β”€β”˜          β””β”€β”€β”€β”¬β”€β”€β”˜  β””β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”¬β”€β”€β”˜          β””β”€β”€β”€β”¬β”€β”€β”˜  β””β”€β”€β”€β”€β”˜   
                                            β”Œβ”€β”€β”€β”€β”€β”€β”          β”Œβ”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”          β”Œβ”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”      β”‚                 β”‚                 β”‚                 β”‚              
 q2 :──────────────────────────────────────── CNOT β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ CNOT β”œβ”€β”€β”€ RZ β”œβ”€β”€β”€ CNOT β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ CNOT β”œβ”€β”€β”€ RZ β”œβ”€β”€β”€β”€β”€β”€β”‚β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”‚β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”‚β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”‚β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
                                            β””β”€β”€β”€β”¬β”€β”€β”˜          β””β”€β”€β”€β”¬β”€β”€β”˜  β””β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”¬β”€β”€β”˜          β””β”€β”€β”€β”¬β”€β”€β”˜  β””β”€β”€β”€β”€β”˜      β”‚                 β”‚                 β”‚                 β”‚              
        β”Œβ”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”          β”Œβ”€β”€β”€β”€β”€β”€β”      β”‚                 β”‚                 β”‚                 β”‚                 β”‚     β”Œβ”€β”€β”€β”€β”      β”‚                 β”‚     β”Œβ”€β”€β”€β”€β”      β”‚              
 q1 :──── RZ β”œβ”€β”€β”€ CNOT β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ CNOT β”œβ”€β”€β”€β”€β”€β”€β”‚β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”‚β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”‚β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”‚β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–ˆβ”€β”€β”€β”€β”€β”€ RX β”œβ”€β”€β”€β”€β”€β”€β–ˆβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–ˆβ”€β”€β”€β”€β”€β”€ RY β”œβ”€β”€β”€β”€β”€β”€β–ˆβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
        β””β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”¬β”€β”€β”˜          β””β”€β”€β”€β”¬β”€β”€β”˜      β”‚                 β”‚                 β”‚                 β”‚                       β””β”€β”€β”€β”€β”˜                              β””β”€β”€β”€β”€β”˜                     
        β”Œβ”€β”€β”€β”€β”      β”‚     β”Œβ”€β”€β”€β”€β”      β”‚         β”‚     β”Œβ”€β”€β”€β”€β”      β”‚                 β”‚     β”Œβ”€β”€β”€β”€β”      β”‚                                                                                      
 q0 :──── RZ β”œβ”€β”€β”€β”€β”€β”€β–ˆβ”€β”€β”€β”€β”€β”€ RX β”œβ”€β”€β”€β”€β”€β”€β–ˆβ”€β”€β”€β”€β”€β”€β”€β”€β”€β–ˆβ”€β”€β”€β”€β”€β”€ RX β”œβ”€β”€β”€β”€β”€β”€β–ˆβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–ˆβ”€β”€β”€β”€β”€β”€ RY β”œβ”€β”€β”€β”€β”€β”€β–ˆβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
        β””β”€β”€β”€β”€β”˜            β””β”€β”€β”€β”€β”˜                      β””β”€β”€β”€β”€β”˜                              β””β”€β”€β”€β”€β”˜                                                                                             

Code

Pull Requests Link Status
MatRenderer πŸ”— Merged
Shifting LaTeX Code and Fixing Draw API πŸ”— Merged
TextRenderer + BaseRenderer + Tests + Documentation πŸ”— Merged
Tutorial Notebooks πŸ”— Final Changes Ongoing

Future Work

  • Update LaTeX Renderer to adopt the BaseRenderer layer system, simplifying maintenance.
  • Imporving test cases to thoroughly evaluate and verify MatRenderer outputs.
  • Development of no-code GUI for quantum circuits to make the library more accessible to a wider audience.

Final Thoughts

This summer has been an incredible experience, as it marked my first time contributing to open source. I was thrilled to be selected for a project that aligned perfectly with my passion for both development and design. My previous experience with Quantum Circuits turned out to be a valuable asset and the project has sparked a strong interest in Quantum Computing.

Being part of this project has been a rewarding experience, allowing me to contribute to something meaningful. I loved being a part of the QuTiP community and am committed to continuing my contributions to the QIP package after GSOC. I am grateful to have had such amazing mentors who guided me throughout the process. I feel fortunate to have worked on a project that ignited my interests and provided opportunities for both personal and professional growth, challenging me to become a better developer.