diff --git a/pyquil/gates.py b/pyquil/gates.py index f583a5ae0..d9147c1ae 100644 --- a/pyquil/gates.py +++ b/pyquil/gates.py @@ -474,7 +474,7 @@ def RESET(qubit_index=None): """ -def MEASURE(qubit, classical_reg=None): +def MEASURE(qubit, classical_reg): """ Produce a MEASURE instruction. diff --git a/pyquil/magic.py b/pyquil/magic.py index e3c9f6664..c44a5d909 100644 --- a/pyquil/magic.py +++ b/pyquil/magic.py @@ -196,7 +196,7 @@ def magicquil(f): @magicquil def fast_reset(q1): - reg1 = MEASURE(q1) + reg1 = MEASURE(q1, None) if reg1: X(q1) else: diff --git a/pyquil/quil.py b/pyquil/quil.py index 074a9a937..bd48ea215 100644 --- a/pyquil/quil.py +++ b/pyquil/quil.py @@ -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: @@ -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 diff --git a/pyquil/quilbase.py b/pyquil/quilbase.py index 0c5e53d7d..6f932365b 100644 --- a/pyquil/quilbase.py +++ b/pyquil/quilbase.py @@ -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): diff --git a/pyquil/tests/test_latex.py b/pyquil/tests/test_latex.py index 7592467ad..e90bbe989 100644 --- a/pyquil/tests/test_latex.py +++ b/pyquil/tests/test_latex.py @@ -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) diff --git a/pyquil/tests/test_parser.py b/pyquil/tests/test_parser.py index e14b538ac..21d49229f 100644 --- a/pyquil/tests/test_parser.py +++ b/pyquil/tests/test_parser.py @@ -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)) diff --git a/pyquil/tests/test_quil.py b/pyquil/tests/test_quil.py index dd47cb803..bb922baa0 100644 --- a/pyquil/tests/test_quil.py +++ b/pyquil/tests/test_quil.py @@ -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): @@ -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() @@ -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)