qiskit icon indicating copy to clipboard operation
qiskit copied to clipboard

template library organization

Open ajavadia opened this issue 4 years ago • 14 comments

The template circuits used in the template optimization pass are currently stored in a directory under qiskit.circuit.library.templates. It would be better to store them in a proper library structure like the EquivalenceLibrary, where each entry in the library can be verified for correctness.

ajavadia avatar Oct 22 '20 00:10 ajavadia

I would like to give this a try, @ajavadia.

born-2learn avatar Oct 27 '20 03:10 born-2learn

hi @born-2learn ! Sorry this felt between the cracks. Are you still interested?

1ucian0 avatar Dec 14 '21 11:12 1ucian0

In addition, currently the picture of the circuit of the template appears as a comment in the code, but not in the documentation. I would suggest to move it in a way that it will appear as part of the documentation.

ShellyGarion avatar Dec 14 '21 12:12 ShellyGarion

I'll work on this, thanks!

born-2learn avatar Jan 14 '22 00:01 born-2learn

Assigned! Thanks @born-2learn

1ucian0 avatar Jan 31 '22 17:01 1ucian0

Hi, I might have to delay working on this issue due to other engagements. Thanks!

born-2learn avatar Feb 07 '22 13:02 born-2learn

Hello @ajavadia can you explain more by giving an example how we should move clifford in temples/clifford folder into the root folder of qisikit.circuit please ?

cometta avatar May 31 '22 13:05 cometta

I can also give it a try, but I need some guidance regrading how to arrange and classify all the circuits at once.

divshacker avatar Jun 02 '22 20:06 divshacker

The goal of this issue is to create a TemplateLibrary class, similar to EquivalenceLibrary, that can be extended with TemplateLibrary.append.

1ucian0 avatar Jun 06 '22 12:06 1ucian0

fyi: @ShellyGarion

If I remember correctly, some of the clifford templates are only "up to the global phase", for instance the template S * H * S * H * S * H = Id.

I am wondering if this needs to be taken into account when reorganizing the templates.

We also have code that verifies templates; and again please note that self.assertTrue(target.equiv(value)) only checks equivalence up to the global phase. `

alexanderivrii avatar Jun 06 '22 13:06 alexanderivrii

Yes. The context for this is this review comment when the original templates were added to Qiskit https://github.com/Qiskit/qiskit-terra/pull/4552#discussion_r455523848

A "template", by definition, is a circuit that is equivalent to the identity. So there must be some check somewhere that prohibits defining invalid templates. The ones that ship with Qiskit should be verified with CI. The user-defined ones must be verified when they are being defined as a template. So one way to do this is to make this a proper datastructure/library that contains various templates and additions to the library are checked. And then have methods for drawing the contents of the library. Also a method to reduce the library to some subset of the circuits would be useful. Then let the TemplateMatching transpiler pass accept a library or a subset of it.

And yes the equivalence to Identity should be exact including global phase.

ajavadia avatar Jun 06 '22 14:06 ajavadia

Clifford group elements and templates are defined up to a global phase, e.g. the template S * H * S * H * S * H = Id is valid only up to a global phase. Perhaps it's worth to add a filed to the templates indicating whether they are equal to id or equivalent up to a global phase?

ShellyGarion avatar Jun 07 '22 07:06 ShellyGarion

Is anyone working on this?

poig avatar Jun 09 '22 00:06 poig

Hi @poig, it seems to me there were some attempts to approach the issues, but no PR open yet. This issue is part of the unitary hack initiative so I think it is fine if more than one person works on this. So feel free to jump in :)

1ucian0 avatar Jun 10 '22 07:06 1ucian0