question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Measuring and Storing

See original GitHub issue

For the code:

p = pq.Program()
p.inst(X(0)).measure(0,1)
print qvm.run(p, [1,0,2])

I would think that the program takes 1 (X[0]), invert it, and print the result as [[0,0,0]]. But the result is [[1,0,0]]. How is this happening?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
willzengcommented, Oct 4, 2017

In Quil all qubits start in the zero state. To change a qubit into the 1 state you can just apply an X gate. For example:

def init_qubits_in_one(qubit_list)
    p = Program()
    for q_index in qubit_list:
        p.inst(X(q_index))
    return p

Will give you a program where all qubits in qubit_list are now in the one state.

1reaction
willzengcommented, Oct 4, 2017

Hi @rasa97 I can tell you a little more about what is happening. This program:

p = pq.Program()
p.inst(X(0)).measure(0,1)

Applies an X gate to the zeroth qubit, placing that qubit in the 1 state. It then measures the state of the zeroth qubit and deposits that bit result in the first classical register. Since the classical registers are initialized in zero, the state of the classical memory at the end of the computation is: [0,1,0] where the first classical register contains the result of the measurement. You’ll get this outcome if you run:

print qvm.run(p, range(3))

to look at the first three bits of classical memory.

When you run:

print qvm.run(p, [1,0,2])

You are asking for the classical memory to be reordered so in the returned list, so that you get the contents of the first bit, the zeroth bit, and the second bit in that order. Thus instead of [0, 1, 0] you get [1, 0, 0] since the classical bit registers have been swapped.

Does that help?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Care and Storage of Measurement Instruments - e2b calibration
Even if you have the best-measuring instruments it would be next to useless if you cannot rely on them to give accurate results....
Read more >
Measuring and storing vessel - Xylem Analytics
Measuring and storing vessel. SKU: 285123170. SKU. Request a Quote. Description. Z 453. Plastic receptacle with squeezing ring sealing and bayonet fastener ...
Read more >
The Smartest Ways to Store Measuring Cups and Spoons
The Smartest Ways to Store Measuring Cups and Spoons · 1. Stick 'em on a knife rack. · 2. Hang them in the...
Read more >
Measuring and Storage Containers - Fiberglass Supply Depot
Measuring and Storage Containers for mixing and measuring various products.
Read more >
You're storing your measuring cups all wrong - The US Sun
In a video posted to TikTok, the expert shared his top tip for organizing measuring spoons and cups so you save space and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found