Skip to content
This repository has been archived by the owner on Aug 18, 2018. It is now read-only.

Commit

Permalink
potential fixes (#15)
Browse files Browse the repository at this point in the history
* potential fixes

* fixing final RuntimeError Travis misses
  • Loading branch information
idk3 authored and babbush committed Oct 1, 2017
1 parent 6e6748c commit 8000e07
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 21 deletions.
6 changes: 2 additions & 4 deletions openfermionprojectq/_ffft.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,7 @@ def ffft_2d(engine, register, system_size):
for i in range(system_size):
ffft(engine, register[system_size*i: system_size*i + system_size],
system_size)
Ph(3 * numpy.pi / 4) | register[system_size*i:
system_size*i + system_size]
Ph(3 * numpy.pi / 4) | register[0]

# To apply the FFFT along the second axis, we must fermionically
# swap qubits into the correct positions. In 2D this is equivalent
Expand All @@ -232,8 +231,7 @@ def ffft_2d(engine, register, system_size):
for i in range(system_size):
ffft(engine, register[system_size*i: system_size*i + system_size],
system_size)
Ph(3 * numpy.pi / 4) | register[system_size*i:
system_size*i + system_size]
Ph(3 * numpy.pi / 4) | register[0]

# Undo the fermionic swap network to restore the original ordering.
for swap in all_swaps[::-1]:
Expand Down
22 changes: 11 additions & 11 deletions openfermionprojectq/_ffft_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ def setUp(self):
self.eng = MainEngine()
self.reg = self.eng.allocate_qureg(3)

def tearDown(self):
All(Measure) | self.reg

def test_apply_phase_1qubit(self):
eng = MainEngine()
reg = eng.allocate_qubit()
Expand All @@ -310,7 +313,6 @@ def test_apply_phase_1qubit(self):
0.06)
Measure | reg

@unittest.skip('simulator problem')
def test_apply_phase_multiple_qubits(self):
All(H) | self.reg
apply_phase(self.reg, 1, 0.07)
Expand Down Expand Up @@ -485,15 +487,11 @@ def test_basic_swap(self):
FermionOperator('4^ 3^ 4 3', -1.0)))


@unittest.skip('simulator problem')
class FFFTPlaneWaveIntegrationTest(unittest.TestCase):

def setUp(self):
random.seed(17)

def tearDown(self):
All(Measure) | self.reg

def test_4mode_ffft_with_external_swaps_all_logical_states(self):
n_qubits = 4

Expand All @@ -505,10 +503,9 @@ def test_4mode_ffft_with_external_swaps_all_logical_states(self):
prepare_logical_state(register, i)

ffft(eng, register, n_qubits)
Ph(3 * numpy.pi / 4) | register
Ph(3 * numpy.pi / 4) | register[0]
eng.flush()
wvfn = ordered_wavefunction(eng)
All(Measure) | register

fermion_operator = prepare_integer_fermion_operator(i)

Expand All @@ -534,6 +531,8 @@ def test_4mode_ffft_with_external_swaps_all_logical_states(self):
index = sum(2 ** site[0] for site in term)
converted_wvfn[index] = ffft_result.terms[term]

All(Measure) | register

self.assertTrue(numpy.allclose(wvfn, converted_wvfn))

def test_8mode_ffft_with_external_swaps_on_single_logical_state(self):
Expand All @@ -548,10 +547,9 @@ def test_8mode_ffft_with_external_swaps_on_single_logical_state(self):
prepare_logical_state(register, state_index)

ffft(eng, register, n_qubits)
Ph(3 * numpy.pi / 4) | register
Ph(3 * numpy.pi / 4) | register[0]
eng.flush()
wvfn = ordered_wavefunction(eng)
All(Measure) | register

fermion_operator = prepare_integer_fermion_operator(state_index)

Expand Down Expand Up @@ -579,6 +577,8 @@ def test_8mode_ffft_with_external_swaps_on_single_logical_state(self):
index = sum(2 ** site[0] for site in term)
converted_wvfn[index] = ffft_result.terms[term]

All(Measure) | register

self.assertTrue(numpy.allclose(wvfn, converted_wvfn))

def test_4mode_ffft_with_external_swaps_equal_expectation_values(self):
Expand Down Expand Up @@ -634,7 +634,7 @@ def test_4mode_ffft_with_external_swaps_equal_expectation_values(self):
All(H) | [db_wavefunction[1], db_wavefunction[3]]

ffft(db_engine, db_wavefunction, n_qubits)
Ph(3 * numpy.pi / 4) | db_wavefunction
Ph(3 * numpy.pi / 4) | db_wavefunction[0]

# Flush the engine and compute expectation values and eigenvalues.
pw_engine.flush()
Expand Down Expand Up @@ -709,7 +709,7 @@ def test_8mode_ffft_with_external_swaps_equal_expectation_values(self):
All(H) | [db_wavefunction[1], db_wavefunction[3]]

ffft(db_engine, db_wavefunction, n_qubits)
Ph(3 * numpy.pi / 4) | db_wavefunction
Ph(3 * numpy.pi / 4) | db_wavefunction[0]

# Flush the engine and compute expectation values and eigenvalues.
pw_engine.flush()
Expand Down
6 changes: 3 additions & 3 deletions openfermionprojectq/_low_depth_trotter_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def simulation_gate_trotter_step(register, hamiltonian, input_ordering=None,
# The single-Z rotation angle is the opposite of the ZZ angle.
Rz(-zz_angle) | register[i]
Rz(-zz_angle) | register[i + 1]
Ph(-zz_angle / 2.) | register
Ph(-zz_angle / 2.) | register[0]

num_operator_left = ((input_ordering[i], 1),
(input_ordering[i], 0))
Expand All @@ -147,7 +147,7 @@ def simulation_gate_trotter_step(register, hamiltonian, input_ordering=None,
# After special_F_adjacent, qubits i and i+1 have swapped;
# the ith rotation must thus be applied to qubit i+1.
Rz(z_angle) | register[i + 1]
Ph(z_angle / 2.) | register
Ph(z_angle / 2.) | register[0]

num_operator_right = ((input_ordering[i+1], 1),
(input_ordering[i+1], 0))
Expand All @@ -164,7 +164,7 @@ def simulation_gate_trotter_step(register, hamiltonian, input_ordering=None,
# After special_F_adjacent, qubits i and i+1 have swapped;
# the (i+1)th rotation must thus be applied to qubit i.
Rz(z_angle) | register[i]
Ph(z_angle / 2.) | register
Ph(z_angle / 2.) | register[0]

# Finally, swap the two modes in input_ordering.
input_ordering[i], input_ordering[i + 1] = (input_ordering[i + 1],
Expand Down
3 changes: 0 additions & 3 deletions openfermionprojectq/_low_depth_trotter_simulation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ def dual_basis_hamiltonian(n_dimensions, system_size,
return normal_ordered(hamiltonian)


@unittest.skip('simulator problem')
class FourQubitSecondOrderTrotterTest(unittest.TestCase):

def setUp(self):
Expand Down Expand Up @@ -425,7 +424,6 @@ def test_simulate_dual_basis_evolution_bad_n_trotter_steps(self):
self.register, FermionOperator(), trotter_steps=0)


@unittest.skip('simulator problem')
class FourQubitFirstOrderEquivalenceWithSecondOrderTest(unittest.TestCase):

def setUp(self):
Expand Down Expand Up @@ -479,7 +477,6 @@ def test_first_order_even_number_of_steps_no_reversal(self):
expected.T))


@unittest.skip('simulator problem')
class HighTrotterNumberIntegrationTest(unittest.TestCase):

def setUp(self):
Expand Down

0 comments on commit 8000e07

Please sign in to comment.