Skip to content
This repository has been archived by the owner on Dec 18, 2021. It is now read-only.

merge Pauli gates for composite blocks #5

Open
Roger-luo opened this issue Mar 22, 2019 · 16 comments
Open

merge Pauli gates for composite blocks #5

Roger-luo opened this issue Mar 22, 2019 · 16 comments

Comments

@Roger-luo
Copy link
Member

Currently only single qubit pauli gate in chain and prod supports merging pauli gates.

Composite blocks like kron and PauliString with pure Pauli gates can be merged by when inside chain/prod as well.

I'll leave this to next release, so we can have some time play with this new optimization pass see what needs to improve.

@Roger-luo
Copy link
Member Author

Fortunately, our simplifier just works for the follow composite blocks (multi-qubits blocks contains single qubits Paulis)

julia> using YaoBlocks

julia> g = chain(2, kron(X, chain(X, Y)), control(2, 1=>X))
nqubits: 2, datatype: Complex{Float64}
chain
├─ kron
│  ├─ 1=>X gate
│  └─ 2=>chain
│     ├─ X gate
│     └─ Y gate
└─ control(2)
   └─ (1,)X gate


julia> simplify(g)
nqubits: 2, datatype: Complex{Float64}
prod
├─ control(2)
│  └─ (1,)X gate
└─ kron
   ├─ 1=>X gate
   └─ 2=>[-im] Z gate

I think next step is to define simplification rules for Cliffords, which will work for multi-qubits circuit in general. Probably this part should be moved to another package in the future, but whoever interested in this feature could start trying YaoBlocks with it now.

@GiggleLiu
Copy link
Member

GiggleLiu commented Apr 5, 2019

Merging pauli gates might be a useful feature.
But please don't use prod in unitary evolutions, this example just shows how terrible it is.

@Roger-luo
Copy link
Member Author

This is useful and this is not related to this issue, see #9. The point to use prod here is just because it's easy to implement. I think eventually these things should be move to a single package for symbolic computing and circuit optimization. But we can use it for now.

@GiggleLiu
Copy link
Member

GiggleLiu commented Apr 6, 2019

it's easy to implement

Not implementing it would be better. For preventing potential errors.

@Roger-luo
Copy link
Member Author

I don't see any potential errors, you can't construct/desctruct a Prod without operators.

@Roger-luo
Copy link
Member Author

The point of #9 is when someone really hit something, it's never too late to make things work. We can't make everything work with one go.

@GiggleLiu
Copy link
Member

when someone really hit something.

I think we both agreed that our development should be demand-driven.
Then, we should remove the Prod, keep the issue and wait for the feature requests. Prod is a replaceable structure, it is almost parallel to chain in functionality.

@Roger-luo
Copy link
Member Author

Roger-luo commented Apr 6, 2019

It's something required for simplify for now, if this is removed, it won't work at all. I don't think remove functionality is a good idea. The point is we could remove Prod after implementation a pass for chain.

It's not something breaking the API, since Prod is just a temporary representation of * and Prod. And not something preventing things not to work.

@GiggleLiu
Copy link
Member

There should not be too much overlap between Prod and ChainBlock, make it possible or remove Prod.

remove Prod after implementation a pass for chain

Don't get this point.

@Roger-luo
Copy link
Member Author

I can just remove Chain's pass so simplify only works for Prod. And add it back when we have time to implement one for Chain.

@GiggleLiu
Copy link
Member

ok, then please also polish the printing

instead of

prod
|- X gate
|- Y gate

print X*Y.

@Roger-luo
Copy link
Member Author

This printing should be a bug. I'll have a look when I'm back.

Ok now */prod strictly corresponding to Prod, nothing else will create a Prod node implicitly. (It's just one line anyway)

@Roger-luo
Copy link
Member Author

@GiggleLiu The printing is correct:

julia> X  * Y
nqubits: 1, datatype: Complex{Float64}
prod
├─ X gate
└─ Y gate

I don't get

prod
|- X gate
|- Y gate

@GiggleLiu
Copy link
Member

I mean, X*Y would be better.

@Roger-luo
Copy link
Member Author

Roger-luo commented Apr 10, 2019

But this will mess up the following

control(2, 1, 2=>X) * kron(X, Y)

which make sense for simplification and basis, etc. (they are Cliffords) and I don't think it's trivial to workaround that. I'd like to keep what it is now, at least it is readable (it won't be readable at all for composite block in a single line).

X * Y only works for primitive blocks, since you don't need multiple lines.

@GiggleLiu
Copy link
Member

you are right.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants