2

I tried to run the starter program demonstrated on this page: http://docs.rigetti.com/en/stable/start.html#installing-the-qvm-and-compiler-on-linux-deb

With the following code:

# construct a Bell State program
p = Program(H(0), CNOT(0, 1))

# run the program on a QVM
qc = get_qc('9q-square-qvm')
result = qc.run_and_measure(p, trials=10)
for i in range(10):
    print(result[i])

And all of result[i]'s turn out to be the same.

Is this expected? If not, what might I be doing wrongly?

glS
  • 27,670
  • 7
  • 39
  • 126

1 Answers1

1

And all of result[i]'s turn out to be the same.

This is what I get from the program you posted:

[1 0 1 0 1 0 1 1 1 0]
[1 0 1 0 1 0 1 1 1 0]
[0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0]
Traceback (most recent call last):
  File "test.py", line 16, in <module>
    print(result[i])
KeyError: 9

The first 2 arrays are not the same as the rest, but they are correlated (that's what happens after CNOT is applied to an H).

The key error is because you are performing a run_and_measure on a 9 qubit device and you are trying to print 10 measurement arrays. Studying the docs for run_and_measure: "This will measure all the qubits on this QuantumComputer, not just qubits that are used in the program. Returns a dictionary keyed by qubit index where the corresponding value is a 1D array of measured bits."

Let's print out result

print(result)
#0: array([1, 1, 0, 1, 1, 0, 0, 0, 0, 0]), 1: array([1, 1, 0, 1, 1, 0, 0, 0, 0, 0]), 2: array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), 3: array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), 4: array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), 5: array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), 6: array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), 7: array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), 8: array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])}

You can see that the 10 different results from run_and_measure of the first qubit and second are the same and the rest are 0's cause we don't apply gates to them.

Victory Omole
  • 2,514
  • 1
  • 10
  • 24