Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/ph gate #151

Merged
merged 2 commits into from Oct 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/fermilib/circuits/_ffft.py
@@ -1,3 +1,17 @@
# Copyright 2017 ProjectQ-Framework (www.projectq.ch)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Functions to perform the fermionic fast Fourier transform."""
import itertools
import numpy
Expand Down Expand Up @@ -209,8 +223,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 @@ -230,8 +243,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: 18 additions & 4 deletions src/fermilib/circuits/_ffft_test.py
@@ -1,3 +1,17 @@
# Copyright 2017 ProjectQ-Framework (www.projectq.ch)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Tests for ffft.py."""
import numpy
import numpy.linalg
Expand Down Expand Up @@ -495,7 +509,7 @@ 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
Expand Down Expand Up @@ -538,7 +552,7 @@ 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
Expand Down Expand Up @@ -624,7 +638,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 @@ -699,7 +713,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
20 changes: 17 additions & 3 deletions src/fermilib/circuits/_low_depth_trotter_simulation.py
@@ -1,3 +1,17 @@
# Copyright 2017 ProjectQ-Framework (www.projectq.ch)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Module for low-depth Trotterized simulation in the plane wave dual basis."""
import functools
import itertools
Expand Down Expand Up @@ -130,7 +144,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 +161,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 +178,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
14 changes: 14 additions & 0 deletions src/fermilib/circuits/_low_depth_trotter_simulation_test.py
@@ -1,3 +1,17 @@
# Copyright 2017 ProjectQ-Framework (www.projectq.ch)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Tests for _low_depth_trotter_simulation.py."""
import numpy
import os
Expand Down