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

PhaseOracle and BooleanExpression allow setting the expression variable order #6658

Merged
merged 22 commits into from
Feb 3, 2023

Conversation

boschmitt
Copy link
Contributor

Summary

This PR add the ability for users to define the variable order when defining a
PhaseOracle. This closes #6499. It depends on #6588.

from qiskit import *
from qiskit.tools.visualization import plot_histogram
from qiskit.circuit.library import PhaseOracle
from qiskit.algorithms import Grover, AmplificationProblem

oracle = PhaseOracle('((A & C) | (B & D)) & ~(C & D)', var_order=['A', 'B', 'C', 'D'])
problem = AmplificationProblem(oracle=oracle, is_good_state=oracle.evaluate_bitstring)
backend = Aer.get_backend('qasm_simulator')
grover = Grover(quantum_instance=backend)
result = grover.amplify(problem)
print(result.circuit_results[0])

The result is {'0101': 237, '1010': 271, '1011': 276, '0111': 240}

Details and comments

The default behaviour is to order variables by appearance in the expression.

Which prints the result: {'0011': 266, '1101': 264, '1100': 241, '0111': 253}

mtreinish and others added 8 commits June 16, 2021 11:39
This commit switches the tweedledum requirement from being optional to a
hard requirement for installing qiskit-terra. We rely on tweedledum to
synthesize phase oracles which is commonly used functionality and several
issues have been opened. This use of tweedledum will likely continue to
grow so we should just list it as a requirement moving forward.

We originally made it optional because the functionality depending on
tweedledum was isolated to just the classical function compiler which
wasn't widely used. There were also packaging issues in the past where
the available precompiled binaries for tweedledum didn't support all of
our supported environments, but those have been resolved. There is still
an issue for arm64 macOS binaries but Qiskit doesn't have wide support
for that yet (although there is a job for terra).

At the same time this commit cleans up the optional requirements list
so that aer is no longer listed there and we add an 'all' extra so that
people can have a simple entypoint to install all the optional extras at
once.

Fixes Qiskit#6333
Fixes Qiskit#1253
Co-authored-by: Bruno Schmitt <bruno.schmitt@epfl.ch>
@boschmitt boschmitt requested a review from a team as a code owner June 29, 2021 12:41
@boschmitt boschmitt changed the title Expression var order PhaseOracle, expression variable order. Jun 29, 2021
@1ucian0
Copy link
Member

1ucian0 commented Jun 29, 2021

On hold, as it depends on #6588.

@1ucian0 1ucian0 added the on hold Can not fix yet label Jun 29, 2021
@boschmitt boschmitt self-assigned this Jun 29, 2021
@1ucian0
Copy link
Member

1ucian0 commented Jul 1, 2021

#6588 is on its way to be merged. So removing on hold

@1ucian0 1ucian0 removed the on hold Can not fix yet label Jul 1, 2021
Co-authored-by: Luciano Bello <bel@zurich.ibm.com>
Copy link
Member

@1ucian0 1ucian0 left a comment

Choose a reason for hiding this comment

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

Do you mind adding some testing and reno?

@1ucian0 1ucian0 changed the title PhaseOracle, expression variable order. PhaseOracle and BooleanExpression allow setting the expression variable order Jul 2, 2021
@1ucian0 1ucian0 added the Changelog: API Change Include in the "Changed" section of the changelog label Jul 2, 2021
@boschmitt boschmitt requested a review from 1ucian0 July 10, 2021 08:13
@HuangJunye HuangJunye added the Community PR PRs from contributors that are not 'members' of the Qiskit repo label Jun 21, 2022
@CLAassistant
Copy link

CLAassistant commented Feb 2, 2023

CLA assistant check
All committers have signed the CLA.

@coveralls
Copy link

coveralls commented Feb 2, 2023

Pull Request Test Coverage Report for Build 4087465935

  • 3 of 3 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 85.245%

Totals Coverage Status
Change from base Build 4083955049: 0.0%
Covered Lines: 67109
Relevant Lines: 78725

💛 - Coveralls

Copy link
Member

@1ucian0 1ucian0 left a comment

Choose a reason for hiding this comment

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

thanks!

@mergify mergify bot merged commit ecc0289 into Qiskit:main Feb 3, 2023
pranay1990 pushed a commit to pranay1990/qiskit-terra that referenced this pull request Feb 9, 2023
…le order (Qiskit#6658)

* Make tweedledum a hard requirement

This commit switches the tweedledum requirement from being optional to a
hard requirement for installing qiskit-terra. We rely on tweedledum to
synthesize phase oracles which is commonly used functionality and several
issues have been opened. This use of tweedledum will likely continue to
grow so we should just list it as a requirement moving forward.

We originally made it optional because the functionality depending on
tweedledum was isolated to just the classical function compiler which
wasn't widely used. There were also packaging issues in the past where
the available precompiled binaries for tweedledum didn't support all of
our supported environments, but those have been resolved. There is still
an issue for arm64 macOS binaries but Qiskit doesn't have wide support
for that yet (although there is a job for terra).

At the same time this commit cleans up the optional requirements list
so that aer is no longer listed there and we add an 'all' extra so that
people can have a simple entypoint to install all the optional extras at
once.

Fixes Qiskit#6333
Fixes Qiskit#1253

* Remove unused imports

* Cleanup docstrings

* black setup

* Update requirements.txt

Co-authored-by: Bruno Schmitt <bruno.schmitt@epfl.ch>

* User defined variable order for oracle expressions

* Fix lint problems

* Update qiskit/circuit/classicalfunction/boolean_expression.py

Co-authored-by: Luciano Bello <bel@zurich.ibm.com>

* Tests and bug-fix

* black

* Add reno

* black

* Consider order in the parameters

* black

---------

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
Co-authored-by: Luciano Bello <bel@zurich.ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: API Change Include in the "Changed" section of the changelog Community PR PRs from contributors that are not 'members' of the Qiskit repo
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Grover's Migration from Aqua to Qiskit Terra
6 participants