Skip to content

Kickoff the arithmetics library#4061

Merged
mergify[bot] merged 38 commits into
Qiskit:masterfrom
Cryoris:library-arithmetic
Apr 7, 2020
Merged

Kickoff the arithmetics library#4061
mergify[bot] merged 38 commits into
Qiskit:masterfrom
Cryoris:library-arithmetic

Conversation

@Cryoris
Copy link
Copy Markdown
Collaborator

@Cryoris Cryoris commented Apr 1, 2020

Summary

Start the arithmetic part of the circuit library. These circuits have been part of Aqua and have been refactored to derive from a circuit and have blueprint-characteristics, i.e. can be lazily constructed and are mutable.

Details and comments

This PR kicks off the development of the arithmetics library. Once this logic moved here we can remove it from Aqua. The integrated classes are:

  • Integer comparator: Compares the value of a qubit register against a fixed integer value. Flips the state of a control qubit depending on the result.
  • Functional Pauli rotations: Apply Pauli rotations based on a function expression, where the argument is the value of a qubit register; RY(f(x))|x>. Note that these can be used to approximate a mapping F|x> |0> -> .. + sqrt(f(x)) |x>|1>.
    • linear Pauli rotations: for linear functions
    • polynomial Pauli rotations: for polynomial functions
    • piecewise linear Pauli rotations: for piecewise linear functions

For a modular design and extensibility, the FunctionalPauliRotations base class has been introduced as base class for all functional Pauli rotations. This is probably also sensible in regard of transpiler passes and circuit optimization, since there exist simplification rules specially for the structures arising from functional rotations.

The tests check both end-to-end results and the mutability of the objects. Ideally we would add a test, that checks that the objects do not break the code in Aqua, but I think this is not supported with the current travis setup (therefore the test is skipped).

Note

This requires the logical or gate from Aqua, which was added -- however this function is not yet properly converted to a Gate.

Cryoris and others added 7 commits April 1, 2020 20:30
* fixed value comparator (now integer comparator)
* linear rotation (now linear Pauli rotations)
* piecewise linear rotation (now piecewise linear pauli rotations)

Co-authored-by: Stefan Woerner <wor@zurich.ibm.com>
Co-authored-by: Almudena Carrera Vazquez <acv@zurich.ibm.com>
@Cryoris Cryoris added this to the 0.13 milestone Apr 1, 2020
Comment thread qiskit/circuit/library/arithmetic/__init__.py
Comment thread qiskit/circuit/library/arithmetic/linear_pauli_rotations.py Outdated
@Cryoris Cryoris changed the title Kickoff the arithmetics library [WIP] Kickoff the arithmetics library Apr 1, 2020
@Cryoris Cryoris changed the title [WIP] Kickoff the arithmetics library Kickoff the arithmetics library Apr 2, 2020
Cryoris and others added 2 commits April 2, 2020 11:13
Co-authored-by: Stefan Woerner <wor@zurich.ibm.com>
Co-authored-by: Manoel Marques <manoel@us.ibm.com>
Co-authored-by: Shaohan Hu <shaohan.hu@ibm.com>
Copy link
Copy Markdown
Member

@ajavadia ajavadia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking good. I checked some parts in detail and others skimmed for now, most comments are about documentation. I'll have another look before merge.

Comment thread qiskit/circuit/library/arithmetic/integer_comparator.py
Comment thread qiskit/circuit/library/__init__.py Outdated
return self._num_state_qubits

@num_state_qubits.setter
def num_state_qubits(self, num_state_qubits: Optional[int]) -> None:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is the setter input optional?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So that the circuit can be "reset" by

circuit.num_state_qubits = None

Maybe an application checks of the number of qubits has been set or not, though I don't have a concrete example where this would be needed. Should I set it to not support None?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's fine. i just see that in this PR some setters accept None and some don't, is that intentional?

Comment thread qiskit/extensions/standard/boolean_logical_gates.py
Comment thread qiskit/circuit/library/arithmetic/weighted_adder.py Outdated
Comment thread test/python/circuit/test_library.py
Comment thread test/python/circuit/test_library.py Outdated
Comment thread test/python/circuit/test_library.py
Comment thread qiskit/circuit/library/arithmetic/weighted_adder.py
Comment thread qiskit/circuit/library/arithmetic/weighted_adder.py Outdated
@Qiskit Qiskit deleted a comment from ajavadia Apr 6, 2020
@mergify mergify Bot merged commit 5571747 into Qiskit:master Apr 7, 2020
faisaldebouni pushed a commit to faisaldebouni/qiskit-terra that referenced this pull request Aug 5, 2020
* add functional rotations base class

* refactor first arithmetic circuits

* fixed value comparator (now integer comparator)
* linear rotation (now linear Pauli rotations)
* piecewise linear rotation (now piecewise linear pauli rotations)

Co-authored-by: Stefan Woerner <wor@zurich.ibm.com>

* integrate polynomial rotations

Co-authored-by: Almudena Carrera Vazquez <acv@zurich.ibm.com>

* update inits

* add tests

* skip test depending on Aqua

* fix imports: no weighted_adder, add functional_rot

* move circ diag in parsed-literal block

* adjust formatting of linear circ diag

* update rendering of docstrings

* move AND/OR gates from Aqua

Co-authored-by: Shaohan Hu <shaohan.hu@ibm.com>
Co-authored-by: Manoel Marques <manoel@us.ibm.com>

* use data getter not _data in copy

* add missing gate inits

* fix imports

* fix lint

* move WSO from aqua

Co-authored-by: Stefan Woerner <wor@zurich.ibm.com>
Co-authored-by: Manoel Marques <manoel@us.ibm.com>
Co-authored-by: Shaohan Hu <shaohan.hu@ibm.com>

* rename to weighted adder

* refactor weighted adder and make a circuit

* updates inits with weighted adder

* add tests for weighted adder

* fix outdated mcu1 import

* add functional pauli rotations import

* Update test/python/circuit/test_library.py

Co-Authored-By: Ali Javadi-Abhari <ajavadia@users.noreply.github.com>

* Update qiskit/circuit/library/arithmetic/weighted_adder.py

Co-Authored-By: Ali Javadi-Abhari <ajavadia@users.noreply.github.com>

* add comment on default behaviour of the weights

* fix rst rendering

* include arithmetic circs in sphinx

* fix copyright

* add _invalidate() method

Co-authored-by: Stefan Woerner <wor@zurich.ibm.com>
Co-authored-by: Almudena Carrera Vazquez <acv@zurich.ibm.com>
Co-authored-by: Shaohan Hu <shaohan.hu@ibm.com>
Co-authored-by: Manoel Marques <manoel@us.ibm.com>
Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants