Probability amplitudes of output states when using StateVector as input

Hi, I’m wondering if there is a way to create a table of amplitudes for output states of an optical circuit when the input state is a StateVector object as opposed to a BasicState.

I see how to get probabilities (or at least approximate them using Sampler), but I’d like to get amplitudes. Alternatively, I see that using a backend and prob_amplitude can give me probability amplitudes of specified output states, but the issue then is that the set_input_state function for backends doesn’t seem to accept StateVector objects, only BasicState objects.

Thanks,
mohan

Hello Mohan,

You won’t be able to use superposed inputs directly on a back-end. However, the Simulator class can do what you’re asking for. It can compute probabilities and evolutions on all pure and mixed states.

Here is an example code to get you on track:

from perceval import Unitary, Simulator, SLOSBackend, StateVector, Matrix

input_state = StateVector([1, 0, 1, 0]) + StateVector([0, 1, 0, 1])  # Create a superposed state

circuit = Unitary(Matrix.random_unitary(4))  # Create any circuit

sim = Simulator(SLOSBackend())  # Use SLOS back-end in a Simulator
sim.set_circuit(circuit)
results = sim.probs(input_state)  # Run your simulation

print(input_state)
print(results)

Outputs:

0.707*|1,0,1,0>+0.707*|0,1,0,1>
{
	|2,0,0,0>: 0.04473871713436912
	|0,1,0,1>: 0.031961342520798616
	|1,0,0,1>: 0.05329046508196197
	|1,1,0,0>: 0.10222962070815501
	|0,0,2,0>: 0.024612467813262918
	|1,0,1,0>: 0.2550024799411448
	|0,2,0,0>: 0.1258443072321124
	|0,1,1,0>: 0.11412042230682148
	|0,0,1,1>: 0.08165216212550813
	|0,0,0,2>: 0.16654801513586562
}

To go further and discover all Simulator features, you may read: Simulator — perceval v0.13 documentation

Best wishes,
Eric

Hi Eric,

Thank you for the quick response, and pointing me to the Simulator class.

I was able to use Simulator, as you suggested, to get probabilities of output states for a StateVector input. Is there a way to also get amplitudes? I see there is a prob_amplitudes method in the class, but it doesn’t seem to be implemented yet? I get a “NotImplementedError” when I try to call it. Is this correct? If so, any plans to implement that method in the near future?

Thanks again for your help.

Cheers,
mohan

Hi Mohan,

With the Simulator, you can evolve your input state into an output StateVector. Retrieving the amplitudes then requires to iterate on this output state:

evolved = sim.evolve(input_state)  # Run your simulation

for basic_state, amplitude in evolved:
    print(basic_state, amplitude)

Cheers,
Eric

Hi Eric,

OK got it. Thanks again for your quick help.

Cheers,
mohan

Hello Eric (and others like Mohan), I have a question which seems closely related:

I am trying to see the amplitude after a Half Wave Plate HWP of \xi = \pi /8

I used
circ_grov = (pcvl.Circuit(2, name = “Grover” ).add(0, pcvl.HWP(np.pi/8)))
pcvl.pdisplay(circ_grov)
backend = pcvl.BackendFactory.get_backend(“SLOS”)
backend.set_circuit(circ_grov)

I get :
AssertionError: Circuit must not contain polarized components

Then I tried
test_HWP_circuit = (pcvl.Circuit(m=2, name=“test_HWP_circuit”)
// pcvl.HWP(sp.pi / 8))
test_HWP_circuit.add((0, 1), pcvl.PBS())# adding HWP to distinguish plarisation

pcvl.pdisplay(test_HWP_circuit)

p = pcvl.Processor(“SLOS”, init_circuit)
input_state = pcvl.BasicState("|{P:H},0>")
ca = pcvl.algorithm.Analyzer(p,[input_state], “*”)
pcvl.pdisplay(ca)
Wich helps but does not quite give the amplitudes either.

I wanted to check the calculations I made by hand on the 2 mode grover circuit available on the documentation:
https://perceval.quandela.net/docs/v0.9/notebooks/2-mode%20Grover%20algorithm.html

Is there any way to do this ?
Thank you in advance
Martin

Hello Martin,

To get polarization amplitudes, you can try the PolarizationSimulator as in the above example by defining sim as:

...

from perceval.simulators import PolarizationSimulator

sim = Simulator(SLOSBackend())
sim = PolarizationSimulator(sim)
sim.set_circuit(circuit)
evolved = sim.evolve(input_state)

for basic_state, amplitude in evolved:
    print(basic_state, amplitude)

Note however that the PolarizationSimulator is not able to handle superposed input states.

I hope this will help you,
Regards,
Aurélien