Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions grove/tests/amplification/test_amplification.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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():
Expand Down
13 changes: 5 additions & 8 deletions grove/tests/deutsch_jozsa/test_deutsch_jozsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()
3 changes: 2 additions & 1 deletion grove/tests/utils/test_utility_programs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from setuptools import setup, find_packages
from grove import __version__

setup(
name="quantum-grove",
version=__version__,
Expand Down