So far, I have my code set up to find the probability distribution using simulator.run(), and I was wondering if I can use the simulator.simulate() function instead to obtain a probability distribution.
The context of my question is quantum walk simulations, but my question doesn't require any knowledge of quantum walks. So, I am looking at quantum walk simulations and want to get the probability distribution of finding the walk in a certain position state (which are represented by the computational basis states of the Hilbert space). The way my code is set up now is as follows: I define the quantum walk in terms of a circuit, where I take a measurement at the end of the circuit (i.e. at the end of each 'walk' I measure which (position) state the walk is found in). I then repeat this process multiple times and find which state is measured each time:
simulator = cirq.Simulator()
result = simulator.run(circuit, repetitions=sample_number)
final = result.histogram(key='x')
Then for 50 repetitions the final looks like Counter({5: 20, 8: 5, 2: 25})
for example, which means that out of 50 runs, I find the walk 20 times in the (position) state 5, 5 times in state 8 etc. I then extract two arrays from this, one with the positions: [5,8,2] and one with the counts: [20,5,25]. I then normalise the latter to obtain probabilities. Then I simply plot these two arrays and find the probability distribution of finding the walk in a certain position.
I was wondering if I can similarly obtain a probability distribution using simulator.simulate() instead of simulator.run(). I still have the same circuit which represents the quantum walk, but now I don't take a measurement, and instead I would like to use
simulator = cirq.Simulator()
result = simulator.simulate(circuit)
Printing the result will give me something like
qubits: (q0, q1, ...) (list of qubits used)
output vector: [0. a. c. ... 0.] (amplitudes of all different states)
It seems like this output vector contains all the information necessary to make a probability distribution: I have the amplitudes of each (position) state, and so squaring them will give me the probability of finding the walk in each state.
The only problem is that I am not sure how to actually 'read' this output vector, and find which state the amplitude corresponds to? For example, is there a way to 'translate' the states in the same way the simulator.run() automatically does (so for 4 qubits, state $|0010\rangle$ becomes $|8\rangle$ in binary, which the final in the run function seems to automatically do)?
Many thanks!