I have implemented Shor's algorithm in Qiskit, and everything works as expected within the IBM Q experience for both the IBM qasm_simulator and real hardware. However, after I've implemented Shors in both Q# and within Braket and attempt to run on either local simulator, the behavior is much more deterministic. On the Q# local simulator, Braket local simulator, Braket managed simulator, and Rigetti Aspen-8 hardware via Braket, however, I get the same results every time. Is this a difference in simulator behavior between IBM and others, or have I messed up somewhere in implementation? Any help would be greatly appreciated.
1 Answer
If you always get the same answer that means the algorithm is running correctly every time, which indeed is the case for simulators that don't incorporate noise characteristics.
One way to check if your system simulates noise is to do a simple program that applies a sequence of effective identity (I) operators with increasing amounts; so for example, in pseudocode:
// Initialize the qubit in the 1 state
X(qubit)
// Artificially wait for time t = numGates * gate time
for (numGates in 1..10) {
for (iteration in 1..numGates) {
// Apply an effective I gate
X(qubit);
X(qubit);
}
M(qubit); // Measure the qubit. For a non-noisy simulator, this should always return 1.
// For a noisy system, this will return 1 for the first iteration, and after that decay to 0.
}
Then measure the qubit and plot the number of gates (times 2 * the X-gate time) on the X axis and the qubit amplitude on the Y axis. If the simulator incorporates noise (and hence qubit decoherence), it will look like an exponentially decaying function. If not, it will return a constant value of 1.
qasm_simulator
is a shot-based simulator ( it is designed to mimic actual quantum computer) so you don't get such deterministic result. Moreover, it actually allows you to add noise calibrated from real-hardware to get even more realistic simulation. Did you add shot noise intoqasm_simulator
when running your circuit? $\endgroup$