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