I am trying to wrap my head around Qiskit Aqua Operators and I stumbled upon this:

My code

hamiltonian=get_hamiltonian(1,1) #a four 4 qubit hamiltonian (Transverse field Ising model)

evo_op1 = evo_op @ (Zero^4)

trotter_op_values=trotter_op.bind_parameters({evo_time: t})


counts1=execute(circuit1, backend=backend, shots=10024).result().get_counts()

for key in counts1.keys():

# I had to instantiate again the trotter_op because trotter_op_values.to_circuit()
#didn't create a new circuit and instead, by having done circuit1.measure_all()
# trotter_op was modified as well.

trotter_op_values=trotter_op.bind_parameters({evo_time: t})

#normalize the results from the circuitsampler
for key in results1.keys():
for key in results1.keys():

# assert counts1.keys()==results1.keys()
assert sum(counts1.values()) #check normalization
assert sum(results1.values()) #check normalization

for key in results1.keys():
    print("state: {} | Counts1: {} | Results1: {}".format(key,counts1[key], results1[key]))

plot_histogram([counts1, results1], legend=["Running the circuit","CircuitSampler from aqua"])

What I expected Since the evo_op1 is just a CircuitStateFn whose initialization was the zero state for the 4 qubits then, passing this into CircuitSampler the CircuitStateFn would be replaced by a DictStateFn whose amplitudes would be the same as measuring all 4 qubits in the trotterization circuit with a zero state initialization (my circuit1).

What I got The histograms never match, for any value of t except t=0. However, there is always a clear similarity between the plots (for small t the probability for 0000 is always the biggest for example and all other states have similiar probabilities, but never exactly equal)

enter image description here

What am I missing? Was it a bad interpretation of the Operator Flow?


Well, you are right. After CircuitSampler you are getting a DictStateFn with phase information lost (see the docs) in the amplitudes and you have to take the square of them for your histogram plot (not normalize).

Besides that, just keep in mind that the number of shots are not stored in the QuantumInstance of CircuitSampler (in the way you are setting them). You should rather do

qinstance = QuantumInstance(backend, shots=10024)
sampler = CircuitSampler(qinstance)
  • $\begingroup$ Thank you! That solved it perfectly. If I may, I added a question a few hours ago about time evolution of a quantum state (quantumcomputing.stackexchange.com/questions/13884/…). Would you say that this is an efficient way to evolve a quantum state in Aqua? Or is there a better way? $\endgroup$ – Bidon Sep 23 '20 at 11:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.