Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

New multiqubit gate #40

Merged
merged 5 commits into from
Dec 20, 2020
Merged

New multiqubit gate #40

merged 5 commits into from
Dec 20, 2020

Conversation

GiggleLiu
Copy link
Member

julia> c1 = chain(5, [ContinuousBlockMarker(put(5, (2,3)=>SWAP), "SWAP"), 
  ContinuousBlockMarker(put(5, 2=>I2), "id"), put(5, 2=>ContinuousBlockMarker(X, "X")),
  control(5, (5,3), (2,4,1)=>ContinuousBlockMarker(put(3, (1,3)=>SWAP), "SWAP"))])

julia> vizcircuit(c1)

image

On the other side, if you try to visualize the following gate, you will get an error.

    c2 = chain(5, [ContinuousBlockMarker(put(5, (2,3)=>SWAP), "SWAP"), ContinuousBlockMarker(put(5, 2=>I2), "id"), put(5, 2=>ContinuousBlockMarker(X, "X")), control(5, (5,3), (2,4,1)=>ContinuousBlockMarker(put(3, (1,2)=>SWAP), "SWAP"))])

@VarLad
Copy link
Contributor

VarLad commented Dec 17, 2020

Great!I hope this gets simplified in the future!Thank you taking the time @GiggleLiu 😄

@GiggleLiu
Copy link
Member Author

GiggleLiu commented Dec 17, 2020

Yeah, but we need a proposal about how to make it simpler. I do not want to insert a name field to the ChainBlock. If you have any interesting idea, feel free to open an issue.

@Roger-luo
Copy link
Member

Can you explain why we need an extra block node? It seems to me a method like nameof is sufficient for determining the name of a block.

@VarLad
Copy link
Contributor

VarLad commented Dec 17, 2020

@Roger-luo Sounds great to me!🙂

@GiggleLiu
Copy link
Member Author

Can you explain why we need an extra block node? It seems to me a method like nameof is sufficient for determining the name of a block.

But the name is not static.

@Roger-luo
Copy link
Member

Roger-luo commented Dec 18, 2020

I think there at least should be a default fallback name for primitive gates, or why ContinuousBlockMarker(put(5, 2=>I2), "id") is not displayed if the user specified it manually? I don't think we should hide any block that user has specified explicitly. we can let ContinuousBlockMarker to change the default name, so the code will look less noisy, e.g

c1 = chain(5, [ContinuousBlockMarker(put(5, (2,3)=>SWAP), "my custom name for SWAP"), 
  ContinuousBlockMarker(put(5, 2=>I2), "explicit id"), put(5, 2=>X),
  control(5, (5,3), put(3, (1,3)=>SWAP))])

where the X gate will be using a default name X, and the block I2 should be displayed explicitly since the user has specified a name for it explicitly (or why should we allow the user to do so?)

on the other hand, what does the word Continuous stands for in ContinuousBlockMarker? can we make it shorter to be just BlockName or something like that?

@GiggleLiu
Copy link
Member Author

I2 is not shown because we use occpied_locs does not count it. Maybe instead of

ContinuousBlockMarker(put(5, (2,3)=>SWAP))

We should use

put(5, (2,3)=>put(5, (2,3)=>LabeledBlock(SWAP, "SWAP"))

@VarLad
Copy link
Contributor

VarLad commented Dec 19, 2020

Whats the problem with,

​put​(​5​, (​2​,​3​)​=>​LabeledBlock​(SWAP, ​"​SWAP​"​))

@VarLad
Copy link
Contributor

VarLad commented Dec 19, 2020

Also, if you could shorten it or make a "lazy" version of LabeledBlock

put​(​5​, (​2​,​3​)​=>​label(SWAP, ​"​SWAP​"​))

This looks perfect!
Can this be done?

@GiggleLiu GiggleLiu closed this Dec 19, 2020
@GiggleLiu GiggleLiu reopened this Dec 19, 2020
@GiggleLiu
Copy link
Member Author

GiggleLiu commented Dec 19, 2020

Whats the problem with,

​put​(​5​, (​2​,​3​)​=>​LabeledBlock​(SWAP, ​"​SWAP​"​))

It can not handle the following gate

ContinuousBlockMarker(chain(5, put(5, 2=>X), put(5, 3=>X)), "XX")

Instead, one has to change the circuit to

chain(5, put(5, (2, 3)=>label(kron(X, X), "XX")))

It is not a big issue, the later looks more intuitive.

@VarLad
Copy link
Contributor

VarLad commented Dec 19, 2020

Instead, one has to change the circuit to

chain(5, put(5, (2, 3)=>label(kron(X, X), "XX")))

It is not a big issue, the later looks more intuitive.

What about

​circuit = chain​(​5​, ​ put​(​2​=>​X), ​put​(​3​=>​X))
XX = chain(5, put(1:5 => label(circuit, "XX"))

@VarLad
Copy link
Contributor

VarLad commented Dec 19, 2020

Just one more thing!
If a given DaggeredBlock has a name/label assigned to it, can you plot it as name/label† in a rectangular box?
This might be the best solution for plotting Daggered Block, other than '

@GiggleLiu
Copy link
Member Author

GiggleLiu commented Dec 19, 2020

You mean this?

chain(5, [put(5, (2,3)=>label(SWAP, "SWAP")'), put(5, 2=>label(I2, "id")), put(5, 2=>label(X, "X")), control(5, (5,3), (2,4,1)=>put(3, (1,3)=>label(SWAP, "SWAP")))]) |> vizcircuit

image

@GiggleLiu
Copy link
Member Author

@Roger-luo good now?

@Roger-luo
Copy link
Member

LGTM

@GiggleLiu
Copy link
Member Author

GiggleLiu commented Dec 19, 2020

We can also use ishermitian to detect whether the content in a labeled block is hermitian, so that we can save a dagger in this case (because the SWAP gate is hermitian).

Which is better?

@VarLad
Copy link
Contributor

VarLad commented Dec 19, 2020

Great!Sounds good to me!
Thanks a lot for taking the time again😄

@GiggleLiu
Copy link
Member Author

GiggleLiu commented Dec 19, 2020

Great!Sounds good to me!
Thanks a lot for taking the time again

Thank you too for providing practical using cases to guide the design of visualization.

@Roger-luo , I think this PR is ready to merge.

@Roger-luo
Copy link
Member

I think we should just follow whatever user is written - we shouldn't perform optimization at this level.

@Roger-luo Roger-luo merged commit 06fe241 into master Dec 20, 2020
@Roger-luo Roger-luo deleted the new-multiqubit branch December 20, 2020 19:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants