qiskit-advocate / qamp-fall-22

Qiskit advocate mentorship program (QAMP) fall 22 cohort (Sep - Dec 2022)
15 stars 7 forks source link

Fix issue "Template optimization fails to recognize simpler circuit" #32

Closed kevinsung closed 1 year ago

kevinsung commented 2 years ago

Description

See https://github.com/Qiskit/qiskit-terra/issues/6974.

Template optimization is an important circuit compilation method which detects gate patterns in a circuit and replaces them with simpler patterns. There is a major issue with the current implementation in Qiskit Terra which causes the template optimization to fail to replace known patterns in certain instances. The task for this project is to research how to fix this issue and implement the fix.

Deliverables

Fix https://github.com/Qiskit/qiskit-terra/issues/6974.

Mentors details

Number of mentees

1

Type of mentees

HaEumKim commented 2 years ago

@kevinsung @GemmaDawson I will do my best in this project ;)

GemmaDawson commented 2 years ago

Please add your Checkpoint 1 presentation materials.

HaEumKim commented 2 years ago

Checkpoint 1 presentation for project https://github.com/qiskit-advocate/qamp-fall-22/issues/32

Fix Template Optimization.pdf

HaEumKim commented 2 years ago

Checkpoint 2

We have found and fixed the bug of our issue loosely. The main strategy we used is adding function "_attempt_bind" from "template_substitution.py" at step where "forward_matching.py" compairs gate of the circuit and template are same or not. This figure shows our code : image

Example 3 of the file attached below shows that our new code resolve bug from Qiskit/qiskit-terra/issues/6974: 32_Fix_Qiskit_qiskit-terra_6974.pdf. The file is little bit messy, because I didn't erase lot of "print()" I used to debug. I need to use them again when I optimize the code ;).

The next step we are going to do is optimize the code, learn how to use git and github, and finally contribute to the issue.

I cite detail information about package and function I mentioned above :

  1. forward_matching.py : Template matching in the forward direction, it takes an initial match, a configuration of qubit and both circuit and template as inputs. The result is a list of match between the template and the circuit.
  2. template_substitution.py : Template matching substitution, given a list of maximal matches it substitutes them in circuit and creates a new optimized dag version of the circuit.
  3. _attempt_bind : Copies the template and attempts to bind any parameters, i.e. attempts to solve for a valid parameter assignment. template_sublist and circuit_sublist match up to the assignment of the parameters.
HaEumKim commented 1 year ago

Final Checkpoint

Every works we have done has been written at checkpoint1&2. We have already fixed the issue, but didn't optimized yet. All the future works will be uploaded at github and communicate at #6974 Template optimization fails to recognize simpler circuit

GemmaDawson commented 1 year ago

Congratulations on completing all the requirements for QAMP Fall 2022!! 🌟🌟🌟