From 8000e07441c028243d6592ab4b774449e4ff85d2 Mon Sep 17 00:00:00 2001 From: idk3 Date: Sat, 30 Sep 2017 17:49:38 -0700 Subject: [PATCH] potential fixes (#15) * potential fixes * fixing final RuntimeError Travis misses --- openfermionprojectq/_ffft.py | 6 ++--- openfermionprojectq/_ffft_test.py | 22 +++++++++---------- .../_low_depth_trotter_simulation.py | 6 ++--- .../_low_depth_trotter_simulation_test.py | 3 --- 4 files changed, 16 insertions(+), 21 deletions(-) diff --git a/openfermionprojectq/_ffft.py b/openfermionprojectq/_ffft.py index 619c1e9..5e85065 100644 --- a/openfermionprojectq/_ffft.py +++ b/openfermionprojectq/_ffft.py @@ -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 @@ -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]: diff --git a/openfermionprojectq/_ffft_test.py b/openfermionprojectq/_ffft_test.py index d839af6..880b4f5 100644 --- a/openfermionprojectq/_ffft_test.py +++ b/openfermionprojectq/_ffft_test.py @@ -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() @@ -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) @@ -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 @@ -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) @@ -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): @@ -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) @@ -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): @@ -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() @@ -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() diff --git a/openfermionprojectq/_low_depth_trotter_simulation.py b/openfermionprojectq/_low_depth_trotter_simulation.py index 1f44473..20d6fa5 100644 --- a/openfermionprojectq/_low_depth_trotter_simulation.py +++ b/openfermionprojectq/_low_depth_trotter_simulation.py @@ -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)) @@ -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)) @@ -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], diff --git a/openfermionprojectq/_low_depth_trotter_simulation_test.py b/openfermionprojectq/_low_depth_trotter_simulation_test.py index ea8a08e..77fcf23 100644 --- a/openfermionprojectq/_low_depth_trotter_simulation_test.py +++ b/openfermionprojectq/_low_depth_trotter_simulation_test.py @@ -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): @@ -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): @@ -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):