Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Definition of (perfect) complex input states #208

Closed
jsenellart opened this issue May 24, 2023 · 5 comments · Fixed by #212
Closed

Definition of (perfect) complex input states #208

jsenellart opened this issue May 24, 2023 · 5 comments · Fixed by #212
Assignees

Comments

@jsenellart
Copy link
Contributor

jsenellart commented May 24, 2023

It is possible today in Perceval to work with complex input state by manually constructing it with pcvl.StateVector - for instance to work with Bell state: 1/sqrt(2)(|01>+|10>) in dual rail encoding, we would do something like that:

sv=pcvl.StateVector(pcvl.BasicState("|1,0,0,1>"))+pcvl.StateVector(pcvl.BasicState("|0,1,1,0>"))

This is used for instance in a simulation as follow:

processor=pcvl.Processor("SLOS", pcvl.Circuit(4).add(1, pcvl.BS()))
processor.with_input(sv)
pcvl.pdisplay(processor.probs()["results"])

A conversion from logical state |01> => |1,0,0,1> already exists through the concept of Processor port:

ls=pcvl.LogicalState([0,1])
print(ls.to_basic_state([pcvl.Port(pcvl.Encoding.DUAL_RAIL, "p1"), pcvl.Port(pcvl.Encoding.DUAL_RAIL, "p2")]))

We would like to have simpler generators of simple and complex states - for a given encoding:

These generators would be available in a StateGenerator class initialized with an encoding (Encoding.RAW (=logical state), Encoding.DUAL_RAIL, and Encoding.POLARIZATION) to be supported

Example code:

>>> generator=pcvl.StateGenerator(Encoding.DUAL_RAIL)
>>> print(generator.LogicalState([0,1]))
|1,0,0,1>
>>> print(generator.BellState("phi+"))
sqrt(2)/2*|1,0,1,0>+sqrt(2)/2*|0,1,0,1>
>>> print(generator.GHZState(3))
sqrt(2)/2*|1,0,1,0,1,0>+sqrt(2)/2*|0,1,0,1,0,1>
>>> graph=nx.path_graph(3)
>>> print(generator.GraphState(graph))
1/sqrt(8)*|1,0,1,0,1,0>+1/sqrt(8)*|0,1,1,0,1,0>+1/sqrt(8)*|1,0,0,1,1,0>+1/sqrt(8)*|1,0,1,0,0,1>+1/sqrt(8)*|0,1,0,1,0,1>-1/sqrt(8)*|1,0,0,1,0,1>-1/sqrt(8)*|0,1,0,1,1,0>+1/sqrt(8)*|0,1,1,0,0,1>
@JMaterne
Copy link
Contributor

Hi, I would like to give this a shot as part of the unitary hack event.

@jsenellart
Copy link
Contributor Author

Hello @JMaterne, Thanks for your interest - let us know if you need help or guidance !

@JMaterne
Copy link
Contributor

Hello, you can find a first version of the StateGenerator class here: https://github.com/JMaterne/Perceval/tree/StateGenerators
Maybe you can take a look if it is what you intended and give guidance what needs to be changed.
I used the same naming convention as in your example code so something like this should work:

>>> generator=pcvl.utils.statevector.StateGenerator(Encoding.DUAL_RAIL)
>>> graph=nx.path_graph(3)
>>> print(generator.GraphState(graph))
sqrt(2)/4*|0,1,1,0,1,0>+sqrt(2)/4*|1,0,1,0,1,0>-sqrt(2)/4*|0,1,0,1,1,0>+...

One thing I noted when testing is that the Polarization Encoding is not yet working with the generator functions.
The problem is that the annotations will be discarded when I take a BasicState with annotations to the power:

>>> print(pcvl.BasicState("|{P:H}>")**2)`
|1,1>
>>> (pcvl.BasicState("|{P:H}>")**2).has_annotations
False

But on the other hand:

>>> print(pcvl.BasicState("|{P:H}>")*pcvl.BasicState("|{P:H}>"))
|{P:H},{P:H}>

This results e.g. in this behaviour:

>>> sg = pcvl.utils.statevector.StateGenerator(pcvl.Encoding.POLARIZATION)
>>> print(sg.GHZState(3))
|1,1,1>

Thanks for your help!

@jsenellart
Copy link
Contributor Author

Hello, I had a quick look, and it looks good ! I created #210 for the issue you found out - can you take a look at the same time since it is in the same file?

Can you also create some test units?

The simplest for further exchanges on the code is that you create a PR.

Thanks

@ericbrts
Copy link
Contributor

ericbrts commented Jun 8, 2023

This issue was completed by @JMaterne

@ericbrts ericbrts closed this as completed Jun 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants