Skip to content

Commit

Permalink
Require classical_reg in Program.measure() and ilk (#821)
Browse files Browse the repository at this point in the history
Closes #248
  • Loading branch information
notmgsk authored Mar 4, 2019
1 parent 08db526 commit a36190b
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pyquil/gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ def RESET(qubit_index=None):
"""


def MEASURE(qubit, classical_reg=None):
def MEASURE(qubit, classical_reg):
"""
Produce a MEASURE instruction.
Expand Down
2 changes: 1 addition & 1 deletion pyquil/magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def magicquil(f):
@magicquil
def fast_reset(q1):
reg1 = MEASURE(q1)
reg1 = MEASURE(q1, None)
if reg1:
X(q1)
else:
Expand Down
5 changes: 3 additions & 2 deletions pyquil/quil.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def inst(self, *instructions):
op = instruction[0]
if op == "MEASURE":
if len(instruction) == 2:
self.measure(instruction[1])
self.measure(instruction[1], None)
else:
self.measure(instruction[1], instruction[2])
else:
Expand Down Expand Up @@ -290,12 +290,13 @@ def no_noise(self):
"""
return self.inst(Pragma("NO-NOISE"))

def measure(self, qubit_index, classical_reg=None):
def measure(self, qubit_index, classical_reg):
"""
Measures a qubit at qubit_index and puts the result in classical_reg
:param int qubit_index: The address of the qubit to measure.
:param int classical_reg: The address of the classical bit to store the result.
Set to None to measure for effect (discard result).
:returns: The Quil Program with the appropriate measure instruction appended, e.g.
MEASURE 0 [1]
:rtype: Program
Expand Down
2 changes: 1 addition & 1 deletion pyquil/quilbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class Measurement(AbstractInstruction):
This is the pyQuil object for a Quil measurement instruction.
"""

def __init__(self, qubit, classical_reg=None):
def __init__(self, qubit, classical_reg):
if not isinstance(qubit, (Qubit, QubitPlaceholder)):
raise TypeError("qubit should be a Qubit")
if classical_reg and not isinstance(classical_reg, MemoryReference):
Expand Down
2 changes: 1 addition & 1 deletion pyquil/tests/test_latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def test_to_latex():
"""A test to give full coverage of latex_generation and latex_config."""
qubits = range(3)
p = Program()
p.inst(X(qubits[0]), Y(qubits[0]), CZ(qubits[0], qubits[2]), SWAP(qubits[0], qubits[1]), MEASURE(qubits[0]),
p.inst(X(qubits[0]), Y(qubits[0]), CZ(qubits[0], qubits[2]), SWAP(qubits[0], qubits[1]), MEASURE(qubits[0], None),
CNOT(qubits[2], qubits[0]))
_ = to_latex(p)

Expand Down
2 changes: 1 addition & 1 deletion pyquil/tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def _expr(expression, expected):


def test_measure():
parse_equals("MEASURE 0", MEASURE(0))
parse_equals("MEASURE 0", MEASURE(0, None))
parse_equals("MEASURE 0 ro[1]", MEASURE(0, 1))


Expand Down
8 changes: 4 additions & 4 deletions pyquil/tests/test_quil.py
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ def test_validate_supported_quil_reset_qubit():

def test_validate_supported_quil_measure_last():
prog = Program(
MEASURE(0),
MEASURE(0, None),
H(0),
)
with pytest.raises(ValueError):
Expand All @@ -1042,7 +1042,7 @@ def test_validate_supported_quil_with_pragma():
RESET(),
H(1),
Pragma('DELAY'),
MEASURE(1)
MEASURE(1, None)
)
assert prog.is_supported_on_qpu()

Expand Down Expand Up @@ -1129,8 +1129,8 @@ def test_validate_supported_quil_multiple_measures():
RESET(),
H(1),
Pragma('DELAY'),
MEASURE(1),
MEASURE(1)
MEASURE(1, None),
MEASURE(1, None)
)
with pytest.raises(ValueError):
validate_supported_quil(prog)
Expand Down

0 comments on commit a36190b

Please sign in to comment.