Mixed states using SVDistribution


I understand that I can use the class SVDistribution in order to define a mixed state, based on StateVector and probabilities.

I can define a state fine, but I am having some trouble using it as an input to a circuit. Are there any examples (or some part of the doc I might have overlooked) that you could share with me?


1 Like

Hello Alexia,

Indeed SVDistributions do not accept anything else than StateVectors in the current code base. However you can still wrap a BasicState in a StateVector, which should give you the same result:

svdist = SVDistribution(StateVector(BasicState('|0,1,0>')))  # This syntax works. The state vector has a probability of 1 of being |0,1,0>

I can’t find any example in the provided notebooks. In order to use a SVDistribution as an input of your circuit, you’re required to retrieve as many input samples as you need, in order to inject each of these input samples into your circuit.

simulator = <any simulation backend>(circuit)
input_samples = svdist.sample(1000)
output_samples = []
for s in input_samples:

You also have to pay attention to balance the probabilities in your SVDistribution if you’re building it from scratch (using its add(sv, probability) method). Ultimately, the sum of probabilities has to be 1.

1 Like