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.

When a method expects qubits as arguments, verify that it received qubits

See original GitHub issue

Currently on_each in SingleQubitGate does this and then calls on in Gate once it is content that is has been given valid arguments. This verification should be moved to on or validate_args in Gate. This is particularly relevant since the signature for on was recently changed from expecting a list of qubits to an unpacked list of qubits. I would push for validate_args since it covers the most cases of user error. If we are going to perform this explicit type-checking anywhere, it makes the most sense in validate_args.

Consider the following example: cirq.X.on(*cirq.LineQubit.range(3)) cirq.X.on_each(*cirq.LineQubit.range(3)) The second line is a valid way to get an op_tree of 3 operations with different qubits all acted on by an X gate. The first will raise an error because cirq.X is a SingleQubitGate and will complain about being applied to 3 qubits.

Now consider this code: cirq.X.on(cirq.LineQubit.range(3)) cirq.X.on_each(cirq.LineQubit.range(3)) The second line raises an error because the list of qubits we passed in isn’t a qubit. The first line doesn’t do this because it doesn’t check that it received qubits and instead only checks that the number of arguments it received is consistent with the number of qubits the gate acts on. Instead the user gets a nonsensical GateOperation object that will give them debugging issues down the line. In fact, cirq.GateOperation(cirq.X, "Q") will also not complain when it should.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
vtomolecommented, Mar 28, 2019

Go for it!

0reactions
timothymancommented, Mar 28, 2019

Can I give this a shot?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Representing Qubit States - Qiskit
You should verify the probability of measuring |1⟩ | 1 ⟩ as an exercise. This rule governs how we get information out of...
Read more >
Chapter 7 Quantum Error Correction
But only if the code is nondegenerate will the density matrix of the t qubits be a multiple of the identity.) To verify...
Read more >
Q Qubit - alpha , beta - Quantum JavaScript
Function ⇒ Q.Qubit Expects no arguments. Calls the non-destructive collapse method, then uses copy$ to overwrite this qubit's values.
Read more >
First quantum computer to pack 100 qubits enters crowded race
The innards of an IBM quantum computer show the tangle of cables used to control and read out its qubits.Credit: IBM.
Read more >
Write & simulate qubit-level programs in Q# - Azure Quantum
In this article. Prerequisites; Allocate qubits and define quantum operations; The complete operation; Test the operation; Add measurements; Run ...
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