Skip to content
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
b887f27
First testing version of Phase Estimation with a lot of hardcoding
Jun 26, 2018
c13e2f3
Adapt to All(Measure)
fernandodelaiglesia Jun 26, 2018
bb5fb57
Adding operators for more than 1 quibit, first version
fernandodelaiglesia Jun 26, 2018
6a18cbf
Adding operators for more than 1 quibit, first versioni: testing
fernandodelaiglesia Jun 26, 2018
8261385
Work in progress: create a PhaseX gate to tests via class
fernandodelaiglesia Jul 17, 2018
630247d
Work in progress: create a PhaseX gate to tests via class. Clean garb…
fernandodelaiglesia Jul 17, 2018
d512a24
Work in progress: create a PhaseX gate to tests via class. Some enhan…
fernandodelaiglesia Jul 18, 2018
764f60a
Work in progress: create a PhaseX gate to tests via class. PhaseX tes…
fernandodelaiglesia Jul 19, 2018
d94be6a
Work in progress: Debugging algorithm
fernandodelaiglesia Jul 19, 2018
50cf592
Work in progress: Debugging algorithm
fernandodelaiglesia Jul 20, 2018
9e81bcc
Adding 2qubit example
Jul 22, 2018
4225eac
adding 2 qubit Gate
fernandodelaiglesia Jul 23, 2018
1f9a4f7
Initial version
fernandodelaiglesia Jul 28, 2018
cf8f58d
Merge branch 'develop' into develop
fernandodelaiglesia Jul 28, 2018
6a4a7f8
Merge remote-tracking branch 'upstream/develop' into develop
fernandodelaiglesia Aug 4, 2018
660cb20
Merge branch 'develop' of https://github.com/fernandodelaiglesia/Proj…
fernandodelaiglesia Aug 4, 2018
143e816
Merge branch 'develop' into develop
fernandodelaiglesia Aug 7, 2018
aed12cd
Merge branch 'develop' into develop
fernandodelaiglesia Aug 11, 2018
4874006
Merge remote-tracking branch 'upstream/develop' into develop
fernandodelaiglesia Aug 11, 2018
34b5abe
Merge branch 'develop' into develop
fernandodelaiglesia Aug 18, 2018
0091149
Merge remote-tracking branch 'upstream/develop' into develop
fernandodelaiglesia Aug 18, 2018
54e7cc2
Create Phase Estimation as a new Gate in operations
fernandodelaiglesia Aug 18, 2018
3ed0b01
Merge branch 'develop' of https://github.com/fernandodelaiglesia/Proj…
fernandodelaiglesia Aug 18, 2018
ac03bdc
Solving travis checks
fernandodelaiglesia Aug 18, 2018
2d37dd4
python 2 compatibility + error in StatePreparation normalization
fernandodelaiglesia Aug 18, 2018
8876d34
test coverage includes now the string
fernandodelaiglesia Aug 18, 2018
ed82cae
Improve the check test for no eigenvector test
fernandodelaiglesia Aug 19, 2018
602e786
Merge branch 'develop' into develop
fernandodelaiglesia Nov 8, 2018
0776589
Merge remote-tracking branch 'upstream/develop' into develop
fernandodelaiglesia Dec 2, 2018
77a84b3
Start modifying to decomposition
fernandodelaiglesia Dec 16, 2018
7a47ab2
Merge branch 'develop' of https://github.com/fernandodelaiglesia/Proj…
fernandodelaiglesia Dec 16, 2018
24f47f6
QPE as decomposition and gate
fernandodelaiglesia Dec 27, 2018
4cfc30f
QPE as decomposition and gate: correct a detail in the test
fernandodelaiglesia Dec 27, 2018
c6e5ebe
try to get the travis-ci freeze solved
fernandodelaiglesia Dec 31, 2018
238f2e1
Resolve merge conflicts in docs/projectq.ops.rst incorporating both l…
fernandodelaiglesia Dec 31, 2018
a072724
Solve a name not defined error in the phaseestimation tests
fernandodelaiglesia Dec 31, 2018
53639e7
Solve coverage in tests
fernandodelaiglesia Dec 31, 2018
8c2d0ea
Merge branch 'develop' into develop
fernandodelaiglesia Jan 19, 2019
2d20b80
Address comments in review + change how to assert the tests
fernandodelaiglesia Jan 20, 2019
1172088
Merge branch 'develop' of https://github.com/fernandodelaiglesia/Proj…
fernandodelaiglesia Jan 20, 2019
a676d29
Enhance statistis in the tests bi more executions
fernandodelaiglesia Jan 20, 2019
393c8f1
Correct bad calculation in tests
fernandodelaiglesia Jan 21, 2019
016248d
Refine test
fernandodelaiglesia Jan 21, 2019
d8262a8
Merge branch 'develop' into develop
fernandodelaiglesia Feb 17, 2019
4f920e3
Merge remote-tracking branch 'upstream/develop' into develop
fernandodelaiglesia Feb 17, 2019
edfa648
Merge branch 'develop' of https://github.com/fernandodelaiglesia/Proj…
fernandodelaiglesia Feb 17, 2019
867fecb
Address Andi comments: add detail in the examples and atributes and r…
fernandodelaiglesia Apr 21, 2019
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
1 change: 1 addition & 0 deletions docs/projectq.ops.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ The operations collection consists of various default gates and is a work-in-pro
projectq.ops.UniformlyControlledRy
projectq.ops.UniformlyControlledRz
projectq.ops.StatePreparation
projectq.ops.QPE
projectq.ops.FlipBits


Expand Down
8 changes: 8 additions & 0 deletions docs/projectq.setups.decompositions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ The decomposition package is a collection of gate decomposition / replacement ru
projectq.setups.decompositions.time_evolution
projectq.setups.decompositions.toffoli2cnotandtgate
projectq.setups.decompositions.uniformlycontrolledr2cnot
projectq.setups.decompositions.phaseestimation


Submodules
Expand Down Expand Up @@ -172,6 +173,13 @@ projectq.setups.decompositions.uniformlycontrolledr2cnot module
:members:
:undoc-members:

projectq.setups.decompositions.phaseestimation module
---------------------------------------------------------------

.. automodule:: projectq.setups.decompositions.phaseestimation
:members:
:undoc-members:


Module contents
---------------
Expand Down
1 change: 1 addition & 0 deletions projectq/ops/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@
from ._uniformly_controlled_rotation import (UniformlyControlledRy,
UniformlyControlledRz)
from ._state_prep import StatePreparation
from ._qpegate import QPE
29 changes: 29 additions & 0 deletions projectq/ops/_qpegate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 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.

from ._basics import BasicGate


class QPE(BasicGate):
"""
Quantum Phase Estimation gate.

See setups.decompositions for the complete implementation
"""
def __init__(self, unitary):
BasicGate.__init__(self)
self.unitary = unitary

def __str__(self):
return "QPE_"+str(self.unitary)
23 changes: 23 additions & 0 deletions projectq/ops/_qpegate_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 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 projectq.ops._qpegate."""

from projectq.ops import _qpegate, X


def test_qpe_str():
unitary = X
gate = _qpegate.QPE(unitary)
assert str(gate) == "QPE_X"
6 changes: 4 additions & 2 deletions projectq/setups/decompositions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
swap2cnot,
toffoli2cnotandtgate,
time_evolution,
uniformlycontrolledr2cnot)
uniformlycontrolledr2cnot,
phaseestimation)

all_defined_decomposition_rules = [
rule
Expand All @@ -54,6 +55,7 @@
swap2cnot,
toffoli2cnotandtgate,
time_evolution,
uniformlycontrolledr2cnot]
uniformlycontrolledr2cnot,
phaseestimation]
for rule in module.all_defined_decomposition_rules
]
97 changes: 97 additions & 0 deletions projectq/setups/decompositions/phaseestimation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Copyright 2018 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.

"""
Registers a decomposition for phase estimation.

(reference https://en.wikipedia.org/wiki/Quantum_phase_estimation_algorithm)

The Quantum Phase Estimation (QPE) executes the algorithm up to the inverse
QFT included. The following steps measuring the ancillas and computing the
phase should be executed outside of the QPE.

The decomposition uses as ancillas (qpe_ancillas) the first qubit/qureg in
the Command and as system qubits teh second qubit/qureg in the Command.

The unitary operator for which the phase estimation is estimated (unitary)
is the gate in Command

Example:
.. code-block:: python

n_qpe_ancillas = 5
qpe_ancillas = eng.allocate_qureg(n_qpe_ancillas)
system_qubits = eng.allocate_qureg(2)
U = unitary_specfic_to_the_problem()

# Apply Quantum Phase Estimation
QPE(U) | (qpe_ancillas, system_qubits)

All(Measure) | qpe_ancillas
# Compute the phase from the ancilla measurement
#(https://en.wikipedia.org/wiki/Quantum_phase_estimation_algorithm)
phasebinlist = [int(q) for q in qpe_ancillas]
phase_in_bin = ''.join(str(j) for j in phasebinlist)
phase_int = int(phase_in_bin,2)
phase = phase_int / (2 ** n_qpe_ancillas)

Attributes:
unitary (BasicGate): Unitary Operation or function to apply
on the system_qubits (e.g.: function(system_qubits, time))

"""

import numpy as np

from projectq.cengines import DecompositionRule
from projectq.meta import Control, Loop, get_control_count
from projectq.ops import H, Tensor, get_inverse, QFT

from projectq.ops import QPE


def _decompose_QPE(cmd):
""" Decompose the Quantum Phase Estimation gate. """
eng = cmd.engine

# Ancillas is the first qubit/qureg. System-qubit is the second qubit/qureg
qpe_ancillas = cmd.qubits[0]
system_qubits = cmd.qubits[1]

# Hadamard on the ancillas
Tensor(H) | qpe_ancillas

# The Unitary Operator
U = cmd.gate.unitary

# Control U on the system_qubits
if (callable(U)):
# If U is a function
for i in range(len(qpe_ancillas)):
with Control(eng, qpe_ancillas[i]):
U(system_qubits, time=2**i)
else:
for i in range(len(qpe_ancillas)):
ipower = int(2**i)
with Loop(eng, ipower):
with Control(eng, qpe_ancillas[i]):
U | system_qubits

# Inverse QFT on the ancillas
get_inverse(QFT) | qpe_ancillas

#: Decomposition rules
all_defined_decomposition_rules = [
DecompositionRule(QPE, _decompose_QPE)
]
Loading