diff --git a/grove/tests/amplification/test_amplification.py b/grove/tests/amplification/test_amplification.py index df7d21a..e5a1aa6 100644 --- a/grove/tests/amplification/test_amplification.py +++ b/grove/tests/amplification/test_amplification.py @@ -56,7 +56,18 @@ def test_amplify(): Test the generic usage of amplify """ # Essentially Grover's to select 011 or 111 - desired = (triple_hadamard.dagger() + + # Note: slight hack here. Technically DAGGER H 0 is equivalent to + # H 0, however since many tests simply test for string equality + # (not program semantic equality) "DAGGER H 0" != "H 0". The + # Program.dagger() operation was changed to use the DAGGER keyword + # in Quil, rather than manually calculate and insert the + # appropriate matrix into the target program. Hence, old tests + # expect that Program("H 0").dagger() == Program("H 0"), but new + # pyquil produces Program("H 0").dagger() == Program("DAGGER H + # 0"). If anything looks weird below, it's probably because of + # this. + desired = (triple_hadamard[::-1] + cz_gate + triple_hadamard.dagger() + diffusion_program(qubits) @@ -67,7 +78,7 @@ def test_amplify(): + diffusion_program(qubits).instructions + triple_hadamard) created = amplification_circuit(triple_hadamard, cz_gate, qubits, iters) - assert desired == created + assert desired.out() == created.out() def test_trivial_diffusion(): diff --git a/grove/tests/deutsch_jozsa/test_deutsch_jozsa.py b/grove/tests/deutsch_jozsa/test_deutsch_jozsa.py index 38e8ee8..9aea19c 100644 --- a/grove/tests/deutsch_jozsa/test_deutsch_jozsa.py +++ b/grove/tests/deutsch_jozsa/test_deutsch_jozsa.py @@ -3,6 +3,7 @@ from unittest.mock import patch from pyquil import Program from pyquil.gates import X, H, CNOT +from pyquil.quilbase import Gate, Qubit from grove.deutsch_jozsa.deutsch_jozsa import DeutschJosza, ORACLE_GATE_NAME @@ -52,25 +53,21 @@ def test_one_qubit_exact_zeros_circuit(): # We've defined the oracle and its dagger. dj_circuit = dj.deutsch_jozsa_circuit - assert len(dj_circuit.defined_gates) == 2 + assert len(dj_circuit.defined_gates) == 1 defined_oracle = None - defined_oracle_inv = None for gate in dj_circuit.defined_gates: if gate.name == ORACLE_GATE_NAME: defined_oracle = gate - else: - defined_oracle_inv = gate assert defined_oracle is not None - assert defined_oracle_inv is not None expected_prog.defgate(defined_oracle.name, defined_oracle.matrix) - expected_prog.defgate(defined_oracle_inv.name, defined_oracle_inv.matrix) expected_prog.inst([X(1), H(1), H(0), - (defined_oracle.name, 2, 0), + Gate(defined_oracle.name, [], list(map(Qubit, [2, 0]))), CNOT(0, 1), - (defined_oracle_inv.name, 2, 0), + Gate(defined_oracle.name, [], list(map(Qubit, [2, 0]))).dagger(), H(0)]) + assert expected_prog.out() == dj.deutsch_jozsa_circuit.out() diff --git a/grove/tests/utils/test_utility_programs.py b/grove/tests/utils/test_utility_programs.py index 61c08fa..f8e1bed 100644 --- a/grove/tests/utils/test_utility_programs.py +++ b/grove/tests/utils/test_utility_programs.py @@ -37,7 +37,8 @@ def double_control_test(instructions, target_qubit, control_qubit_one, control_q assert instructions[1].name == CNOT(control_qubit_one, control_qubit_two).name assert instructions[1].qubits == [control_qubit_one, control_qubit_two] - assert instructions[2].name == cpg.format_gate_name("C", sqrt_z) + '-INV' + assert instructions[2].name == cpg.format_gate_name("C", sqrt_z) + assert instructions[2].modifiers == ["DAGGER"] assert instructions[2].qubits == [control_qubit_two, target_qubit] assert instructions[3].name == CNOT(control_qubit_one, control_qubit_two).name diff --git a/setup.py b/setup.py index fb540b8..de84fcb 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,7 @@ from setuptools import setup, find_packages from grove import __version__ - + setup( name="quantum-grove", version=__version__,