zxcalc / pyzx

Python library for quantum circuit rewriting and optimisation using the ZX-calculus
Apache License 2.0
365 stars 108 forks source link

Unable reach the diagram of depth 6 for Cliffords #94

Closed danielecuomo closed 1 year ago

danielecuomo commented 2 years ago

As stated in Graph-theoretic Simplification of Quantum Circuits with the ZX-calculus, a Clifford circuit can always be transformed in a graph-like diagram corresponding with a sub-diagram occurring in the middle and performing parity-checks -- see equation (11) of the above paper.

However I can't reach this form but only a similar one. And I struggle to understand what are the steps to reach this form.

I posted such issue also at the link below.

https://quantumcomputing.stackexchange.com/questions/27162/pyzx-optimisation-steps-for-clifford-circuits?noredirect=1#comment35564_27162

jvdwetering commented 2 years ago

To get to the form on the right you unfuse the CZ gates and phases and colour change the right-most layer of spiders to X-spiders by pushing out Hadamards. I think this is also the way it is explained in the paper right? Is there a particular step that is unclear?

danielecuomo commented 2 years ago

It is clear in theory, especially by reading the paper. However, when using the built-in methods, I can't obtain the CZ layers.

Below the steps I do:

random.seed(10)
g = zx.generate.cliffordT(qubits=6, depth=6, p_t=None, p_s=0.2, p_hsh=0.2, p_cnot=0.6)
zx.simplify.interior_clifford_simp(g)
g.normalize()
zx.simplify.to_rg(g, select = lambda v: set(g.neighbors(v)).intersection(g.outputs()))
jvdwetering commented 2 years ago

Ah yeah, I don't think there currently is a built-in way to do that, apart from what is implemented in the extract_circuit method. It shouldn't be too hard to implement it yourself though: find all the spiders connected to an input, and then for every Hadamard connection between these spiders, unfuse a spider into a CZ (this is essentially what extract_circuit does, but then immediately unto a Circuit, while I think you are wanting to keep it in the form of a Graph?).

danielecuomo commented 2 years ago

Yes, I'd like to reach that Graph and then implement my own extract_circuit method.

danielecuomo commented 1 year ago

Sorry but the extract circuit also makes some changes on the final circuit, because I can see that the normal form is not preserved. Am I right?

danielecuomo commented 1 year ago

For example extracting a circuit starting from the following generation: g = zx.generate.cliffordT(qubits = 4, depth = 16, p_s=0.2, p_hsh=0.2, p_cnot=0.6)

danielecuomo commented 1 year ago

In alternative I tried to use the extract_simple method. But I get the error: Algorithm failed: Graph is not fully reduced

jvdwetering commented 1 year ago

So the problem I think is that the extract_circuit method does it in such a way that it generates both CNOTs and CZs during extraction. You can probably get it back to the correct form by pushing some Hadamards through CZs to turn them into CNOTs. But this is all not implemented in a method. I might get around to implementing a method that given a Clifford normal form, spits out a circuit of the form described in the paper, but this is currently not high on my todo list.

Is there a specific project or thing you need it for?

danielecuomo commented 1 year ago

My paper on https://arxiv.org/abs/2112.14139 will be soon published on ACM Transactions on Quantum Computing.

I perform a distributed compilation over Clifford in normal forms. In such a paper I just give a numerical evaluation starting from random normal forms.

In order to use the library pyzx I need it to be able to give in output a Clifford circuit in normal form.

danielecuomo commented 1 year ago

The case in the picture doesn't look to me like something that I can bring back to the normal form.

Screenshot 2022-11-17 at 11 01 19
jvdwetering commented 1 year ago

Yeah I don't exactly see how that corresponds to a normal form either, weird. Okay, I'll look into making a dedicated function for this, because it would be a nice thing to have.

danielecuomo commented 1 year ago

Great! Thanks a lot. Looking forward to use it!

danielecuomo commented 1 year ago

Greetings, Is there any news? Thank you!

jvdwetering commented 1 year ago

Sorry, I got distracted with other things. The function I just added should do what you asked. Now that I am at it I also want to add a function that also immediately converts it to a Circuit.

danielecuomo commented 1 year ago

Great, thank you!

jvdwetering commented 1 year ago

And now also implemented a new function zx.extract.extract_clifford_normal_form that immediately gives you a circuit out.

jvdwetering commented 1 year ago

Can I close this issue?

danielecuomo commented 1 year ago

I already closed it.

Daniele

On 8 Jun 2023, at 15:34, John van de Wetering @.***> wrote:

Can I close this issue?

— Reply to this email directly, view it on GitHub https://github.com/Quantomatic/pyzx/issues/94#issuecomment-1582591640, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJBFE5O3PFDWFPXSMVZW2Y3XKHIHVANCNFSM522MNG6Q. You are receiving this because you modified the open/close state.