Skip to content

Commit

Permalink
fixing tests to work with pyquil1.9, in particular due to pauli ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
ampolloreno committed Jun 7, 2018
1 parent 8dc58c7 commit 5b3b207
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
4 changes: 2 additions & 2 deletions grove/alpha/fermion_transforms/tests/test_bravyi_kitaev.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def test_hardcoded_transform():
x = bkt.kill(9)
y = bkt.create(9)

assert str(x) == '0.5j*Z7*Y9*X11*X15 + (0.5+0j)*Z7*Z8*X9*X11*X15'
assert str(y) == '-0.5j*Z7*Y9*X11*X15 + (0.5+0j)*Z7*Z8*X9*X11*X15'
assert str(x) == '(0.5+0j)*X9*Z7*Z8*X11*X15 + 0.5j*Y9*X11*X15*Z7'
assert str(y) == '(0.5+0j)*X9*Z7*Z8*X11*X15 + -0.5j*Y9*X11*X15*Z7'


def test_term_length():
Expand Down
4 changes: 3 additions & 1 deletion grove/pyqaoa/qaoa.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def __init__(self, qvm, qubits, steps=1, init_betas=None,
Contains all information for running the QAOA algorthm to find the
ground state of the list of cost clauses.
N.B. This only works if all the terms in the cost Hamiltonian commute with each other.
:param qvm: (Connection) The qvm connection to use for the algorithm.
:param qubits: (list of ints) The number of qubits to use for the algorithm.
:param steps: (int) The number of mixing and cost function steps to use.
Expand Down Expand Up @@ -124,7 +126,7 @@ def __init__(self, qvm, qubits, steps=1, init_betas=None,
def get_parameterized_program(self):
"""
Return a function that accepts parameters and returns a new Quil
program
program.
:returns: a function
"""
Expand Down
11 changes: 7 additions & 4 deletions grove/tests/measurements/test_estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,14 @@ def test_rotation_programs():
Testing the generation of post rotations
"""
test_term = sZ(0) * sX(20) * sI(100) * sY(5)
# note: string comparison of programs requires gates to be in the same order
true_rotation_program = Program().inst(
[RX(np.pi / 2)(5), RY(-np.pi / 2)(20)])
rotations_to_do = [RX(np.pi / 2)(5), RY(-np.pi / 2)(20)]
test_rotation_program = get_rotation_program(test_term)
assert true_rotation_program.out() == test_rotation_program.out()
# Since the rotations commute, it's sufficient to test membership in the program,
# without ordering. However, it's true that a more complicated rotation could be performed,
# where the elements would not be free to be permuted. We ignore this possibility, for now.
assert len(rotations_to_do) == len(test_rotation_program)
for rotation in test_rotation_program:
assert rotation in rotations_to_do


def test_get_parity():
Expand Down
10 changes: 5 additions & 5 deletions grove/tests/pyqaoa/test_maxcut.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ def test_param_prog_p1_barbell():

param_prog = inst.get_parameterized_program()
trial_prog = param_prog([1.2, 3.4])
result_prog = Program().inst([H(0), H(1), X(0), PHASE(1.7)(0), X(0),
PHASE(1.7)(0), CNOT(0, 1), RZ(3.4)(1),
CNOT(0, 1), H(0), RZ(-2.4)(0), H(0), H(1),
result_prog = Program().inst([H(0), H(1), CNOT(0, 1), RZ(3.4)(1),
CNOT(0, 1), X(0), PHASE(1.7)(0), X(0),
PHASE(1.7)(0), H(0), RZ(-2.4)(0), H(0), H(1),
RZ(-2.4)(1), H(1)])
trial_prog == result_prog

Expand All @@ -89,12 +89,12 @@ def test_psiref_bar_p2():
# returns are the rotations correct?
prog = param_prog([1.2, 3.4, 2.1, 4.5])
result_prog = Program().inst([H(0), H(1),
X(0), PHASE(1.05)(0), X(0), PHASE(1.05)(0),
CNOT(0, 1), RZ(2.1)(1), CNOT(0, 1),
X(0), PHASE(1.05)(0), X(0), PHASE(1.05)(0),
H(0), RZ(-2.4)(0), H(0),
H(1), RZ(-2.4)(1), H(1),
X(0), PHASE(2.25)(0), X(0), PHASE(2.25)(0),
CNOT(0, 1), RZ(4.5)(1), CNOT(0, 1),
X(0), PHASE(2.25)(0), X(0), PHASE(2.25)(0),
H(0), RZ(-6.8)(0), H(0),
H(1), RZ(-6.8)(1), H(1),
])
Expand Down

0 comments on commit 5b3b207

Please sign in to comment.