Closed RobertWezemanTNO closed 2 years ago
It was pointed out to me that adding the flag full_state_projection=True
will solve my problems.
...
result = qi.execute_qasm(qasm, backend_type=backend_type, number_of_shots=1, full_state_projection=True)
print(result['histogram'])
# OrderedDict([('0', 0.25), ('1', 0.25), ('2', 0.25), ('3', 0.25)])
Or with more shots
...
result = qi.execute_qasm(qasm, backend_type=backend_type, number_of_shots=1024, full_state_projection=True)
print(result['histogram'])
# OrderedDict([('1', 0.24609375), ('0', 0.2470703125), ('2', 0.23828125), ('3', 0.2685546875)])
It is however still unclear to me what the default setting full_state_projection=False
is supposed to return and why it always returns OrderedDict([('0', 1.0)])
.
Note: the default value for full_state_projection
for API-calls execute_qasm
and execute_qasm_async
was changed in SDK Feature release 1.2.0 from True
to False
. See Release Notes 2020-05-15.
The reason why execute_qasm(qasm, backend_type=backend_type, full_state_projection=False)
always resulted in a null output was because the qasm-code did not contain measurements of qubits. In this case a null output is the same as a measurement of the zero state.
The following qasm-code yields the expected results.
qasm = '''version 1.0
qubits 2
H q[0]
CNOT q[0], q[1]
H q[0]
Measure q[0,1]
'''
This might need to be updated in the code-example in the README.
This issue can be closed.
@RobertWezemanTNO Hi Robert, I will update the example in the README. Thanks for the suggestion.
Bug report
What did you try to do?
When I execute circuits using execute_qasm, I get thrown an experiment optimization warning with the message that the experiment might take longer to execute. The obtained results are wrong. For example, when I execute the following code
The resulting print statement is
Which is not the correct output for this simple circuit. When I look in My QI, I see the correct circuit with the wrong results. When I execute the circuit again from within MyQI everything seems to work just fine. When I execute the same code using Qiskit everything seems to work for me.
What did you expect to happen?
Output for the given example:
What actually happened?
Output for the given example:
Environment
Please specify: