qiskit-optimization


Nameqiskit-optimization JSON
Version 0.6.1 PyPI version JSON
download
home_pagehttps://github.com/qiskit-community/qiskit-optimization
SummaryQiskit Optimization: A library for optimization applications using quantum computing
upload_time2024-02-28 02:53:24
maintainer
docs_urlNone
authorQiskit Optimization Development Team
requires_python>=3.8
licenseApache-2.0
keywords qiskit sdk quantum optimization
VCS
bugtrack_url
requirements qiskit qiskit-algorithms scipy numpy docplex setuptools networkx
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Qiskit Optimization

[![License](https://img.shields.io/github/license/Qiskit/qiskit-optimization.svg?style=popout-square)](https://opensource.org/licenses/Apache-2.0)

**Qiskit Optimization** is an open-source framework that covers the whole range from high-level modeling of optimization
problems, with automatic conversion of problems to different required representations, to a suite
of easy-to-use quantum optimization algorithms that are ready to run on classical simulators,
as well as on real quantum devices via Qiskit.

The Optimization module enables easy, efficient modeling of optimization problems using
[docplex](https://ibmdecisionoptimization.github.io/docplex-doc/).
A uniform interface as well as automatic conversion between different problem representations
allows users to solve problems using a large set of algorithms, from variational quantum algorithms,
such as the Quantum Approximate Optimization Algorithm QAOA, to Grover Adaptive Search using the
GroverOptimizer, leveraging fundamental algorithms provided by
[Qiskit Algorithms](https://qiskit-community.github.io/qiskit-algorithms/). Furthermore, the modular design
of the optimization module allows it to be easily extended and facilitates rapid development and
testing of new algorithms. Compatible classical optimizers are also provided for testing,
validation, and benchmarking.

## Installation

We encourage installing Qiskit Optimization via the pip tool (a python package manager).

```bash
pip install qiskit-optimization
```

**pip** will handle all dependencies automatically and you will always install the latest
(and well-tested) version.

If you want to work on the very latest work-in-progress versions, either to try features ahead of
their official release or if you want to contribute to Optimization, then you can install from source.
To do this follow the instructions in the
 [documentation](https://qiskit-community.github.io/qiskit-optimization/getting_started.html#installation).


----------------------------------------------------------------------------------------------------

### Optional Installs

* **IBM CPLEX** may be installed using `pip install 'qiskit-optimization[cplex]'` to enable the reading of `LP` files and the usage of
  the `CplexOptimizer`, wrapper for ``cplex.Cplex``. CPLEX is a separate package and its support of Python versions is independent of Qiskit Optimization, where this CPLEX command will have no effect if there is no compatible version of CPLEX available (yet).

* **CVXPY** may be installed using the command `pip install 'qiskit-optimization[cvx]'`.
  CVXPY being installed will enable the usage of the Goemans-Williamson algorithm as an optimizer `GoemansWilliamsonOptimizer`.

* **Matplotlib** may be installed using the command `pip install 'qiskit-optimization[matplotlib]'`.
  Matplotlib being installed will enable the usage of the `draw` method in the graph optimization application classes.

* **Gurobipy** may be installed using the command `pip install 'qiskit-optimization[gurobi]'`.
  Gurobipy being installed will enable the usage of the GurobiOptimizer.

### Creating Your First Optimization Programming Experiment in Qiskit

Now that Qiskit Optimization is installed, it's time to begin working with the optimization module.
Let's try an optimization experiment to compute the solution of a
[Max-Cut](https://en.wikipedia.org/wiki/Maximum_cut). The Max-Cut problem can be formulated as
quadratic program, which can be solved using many several different algorithms in Qiskit.
In this example, the MinimumEigenOptimizer
is employed in combination with the Quantum Approximate Optimization Algorithm (QAOA) as minimum
eigensolver routine.

```python
from docplex.mp.model import Model

from qiskit_optimization.algorithms import MinimumEigenOptimizer
from qiskit_optimization.translators import from_docplex_mp

from qiskit.primitives import Sampler

from qiskit_algorithms.utils import algorithm_globals
from qiskit_algorithms import QAOA
from qiskit_algorithms.optimizers import SPSA

# Generate a graph of 4 nodes
n = 4
edges = [(0, 1, 1.0), (0, 2, 1.0), (0, 3, 1.0), (1, 2, 1.0), (2, 3, 1.0)]  # (node_i, node_j, weight)

# Formulate the problem as a Docplex model
model = Model()

# Create n binary variables
x = model.binary_var_list(n)

# Define the objective function to be maximized
model.maximize(model.sum(w * x[i] * (1 - x[j]) + w * (1 - x[i]) * x[j] for i, j, w in edges))

# Fix node 0 to be 1 to break the symmetry of the max-cut solution
model.add(x[0] == 1)

# Convert the Docplex model into a `QuadraticProgram` object
problem = from_docplex_mp(model)

# Run quantum algorithm QAOA on qasm simulator
seed = 1234
algorithm_globals.random_seed = seed

spsa = SPSA(maxiter=250)
sampler = Sampler()
qaoa = QAOA(sampler=sampler, optimizer=spsa, reps=5)
algorithm = MinimumEigenOptimizer(qaoa)
result = algorithm.solve(problem)
print(result.prettyprint())  # prints solution, x=[1, 0, 1, 0], the cost, fval=4
```

### Further examples

Learning path notebooks may be found in the
[optimization tutorials](https://qiskit-community.github.io/qiskit-optimization/tutorials/index.html) section
of the documentation and are a great place to start.

----------------------------------------------------------------------------------------------------

## Contribution Guidelines

If you'd like to contribute to Qiskit, please take a look at our
[contribution guidelines](https://github.com/qiskit-community/qiskit-optimization/blob/main/CONTRIBUTING.md).
This project adheres to Qiskit's [code of conduct](https://github.com/qiskit-community/qiskit-optimization/blob/main/CODE_OF_CONDUCT.md).
By participating, you are expected to uphold this code.

We use [GitHub issues](https://github.com/qiskit-community/qiskit-optimization/issues) for tracking requests and bugs. Please
[join the Qiskit Slack community](https://qisk.it/join-slack)
and for discussion and simple questions.
For questions that are more suited for a forum, we use the **Qiskit** tag in [Stack Overflow](https://stackoverflow.com/questions/tagged/qiskit).

## Authors and Citation

Optimization was inspired, authored and brought about by the collective work of a team of researchers.
Optimization continues to grow with the help and work of
[many people](https://github.com/qiskit-community/qiskit-optimization/graphs/contributors), who contribute
to the project at different levels.
If you use Qiskit, please cite as per the provided
[BibTeX file](https://github.com/Qiskit/qiskit/blob/main/CITATION.bib).

## License

This project uses the [Apache License 2.0](https://github.com/qiskit-community/qiskit-optimization/blob/main/LICENSE.txt).

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/qiskit-community/qiskit-optimization",
    "name": "qiskit-optimization",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "qiskit sdk quantum optimization",
    "author": "Qiskit Optimization Development Team",
    "author_email": "qiskit@us.ibm.com",
    "download_url": "https://files.pythonhosted.org/packages/80/63/30ae1aa61c407ccd7f2a1499884653cf6be87fd4a216013c226273796a8f/qiskit-optimization-0.6.1.tar.gz",
    "platform": null,
    "description": "# Qiskit Optimization\n\n[![License](https://img.shields.io/github/license/Qiskit/qiskit-optimization.svg?style=popout-square)](https://opensource.org/licenses/Apache-2.0)\n\n**Qiskit Optimization** is an open-source framework that covers the whole range from high-level modeling of optimization\nproblems, with automatic conversion of problems to different required representations, to a suite\nof easy-to-use quantum optimization algorithms that are ready to run on classical simulators,\nas well as on real quantum devices via Qiskit.\n\nThe Optimization module enables easy, efficient modeling of optimization problems using\n[docplex](https://ibmdecisionoptimization.github.io/docplex-doc/).\nA uniform interface as well as automatic conversion between different problem representations\nallows users to solve problems using a large set of algorithms, from variational quantum algorithms,\nsuch as the Quantum Approximate Optimization Algorithm QAOA, to Grover Adaptive Search using the\nGroverOptimizer, leveraging fundamental algorithms provided by\n[Qiskit Algorithms](https://qiskit-community.github.io/qiskit-algorithms/). Furthermore, the modular design\nof the optimization module allows it to be easily extended and facilitates rapid development and\ntesting of new algorithms. Compatible classical optimizers are also provided for testing,\nvalidation, and benchmarking.\n\n## Installation\n\nWe encourage installing Qiskit Optimization via the pip tool (a python package manager).\n\n```bash\npip install qiskit-optimization\n```\n\n**pip** will handle all dependencies automatically and you will always install the latest\n(and well-tested) version.\n\nIf you want to work on the very latest work-in-progress versions, either to try features ahead of\ntheir official release or if you want to contribute to Optimization, then you can install from source.\nTo do this follow the instructions in the\n [documentation](https://qiskit-community.github.io/qiskit-optimization/getting_started.html#installation).\n\n\n----------------------------------------------------------------------------------------------------\n\n### Optional Installs\n\n* **IBM CPLEX** may be installed using `pip install 'qiskit-optimization[cplex]'` to enable the reading of `LP` files and the usage of\n  the `CplexOptimizer`, wrapper for ``cplex.Cplex``. CPLEX is a separate package and its support of Python versions is independent of Qiskit Optimization, where this CPLEX command will have no effect if there is no compatible version of CPLEX available (yet).\n\n* **CVXPY** may be installed using the command `pip install 'qiskit-optimization[cvx]'`.\n  CVXPY being installed will enable the usage of the Goemans-Williamson algorithm as an optimizer `GoemansWilliamsonOptimizer`.\n\n* **Matplotlib** may be installed using the command `pip install 'qiskit-optimization[matplotlib]'`.\n  Matplotlib being installed will enable the usage of the `draw` method in the graph optimization application classes.\n\n* **Gurobipy** may be installed using the command `pip install 'qiskit-optimization[gurobi]'`.\n  Gurobipy being installed will enable the usage of the GurobiOptimizer.\n\n### Creating Your First Optimization Programming Experiment in Qiskit\n\nNow that Qiskit Optimization is installed, it's time to begin working with the optimization module.\nLet's try an optimization experiment to compute the solution of a\n[Max-Cut](https://en.wikipedia.org/wiki/Maximum_cut). The Max-Cut problem can be formulated as\nquadratic program, which can be solved using many several different algorithms in Qiskit.\nIn this example, the MinimumEigenOptimizer\nis employed in combination with the Quantum Approximate Optimization Algorithm (QAOA) as minimum\neigensolver routine.\n\n```python\nfrom docplex.mp.model import Model\n\nfrom qiskit_optimization.algorithms import MinimumEigenOptimizer\nfrom qiskit_optimization.translators import from_docplex_mp\n\nfrom qiskit.primitives import Sampler\n\nfrom qiskit_algorithms.utils import algorithm_globals\nfrom qiskit_algorithms import QAOA\nfrom qiskit_algorithms.optimizers import SPSA\n\n# Generate a graph of 4 nodes\nn = 4\nedges = [(0, 1, 1.0), (0, 2, 1.0), (0, 3, 1.0), (1, 2, 1.0), (2, 3, 1.0)]  # (node_i, node_j, weight)\n\n# Formulate the problem as a Docplex model\nmodel = Model()\n\n# Create n binary variables\nx = model.binary_var_list(n)\n\n# Define the objective function to be maximized\nmodel.maximize(model.sum(w * x[i] * (1 - x[j]) + w * (1 - x[i]) * x[j] for i, j, w in edges))\n\n# Fix node 0 to be 1 to break the symmetry of the max-cut solution\nmodel.add(x[0] == 1)\n\n# Convert the Docplex model into a `QuadraticProgram` object\nproblem = from_docplex_mp(model)\n\n# Run quantum algorithm QAOA on qasm simulator\nseed = 1234\nalgorithm_globals.random_seed = seed\n\nspsa = SPSA(maxiter=250)\nsampler = Sampler()\nqaoa = QAOA(sampler=sampler, optimizer=spsa, reps=5)\nalgorithm = MinimumEigenOptimizer(qaoa)\nresult = algorithm.solve(problem)\nprint(result.prettyprint())  # prints solution, x=[1, 0, 1, 0], the cost, fval=4\n```\n\n### Further examples\n\nLearning path notebooks may be found in the\n[optimization tutorials](https://qiskit-community.github.io/qiskit-optimization/tutorials/index.html) section\nof the documentation and are a great place to start.\n\n----------------------------------------------------------------------------------------------------\n\n## Contribution Guidelines\n\nIf you'd like to contribute to Qiskit, please take a look at our\n[contribution guidelines](https://github.com/qiskit-community/qiskit-optimization/blob/main/CONTRIBUTING.md).\nThis project adheres to Qiskit's [code of conduct](https://github.com/qiskit-community/qiskit-optimization/blob/main/CODE_OF_CONDUCT.md).\nBy participating, you are expected to uphold this code.\n\nWe use [GitHub issues](https://github.com/qiskit-community/qiskit-optimization/issues) for tracking requests and bugs. Please\n[join the Qiskit Slack community](https://qisk.it/join-slack)\nand for discussion and simple questions.\nFor questions that are more suited for a forum, we use the **Qiskit** tag in [Stack Overflow](https://stackoverflow.com/questions/tagged/qiskit).\n\n## Authors and Citation\n\nOptimization was inspired, authored and brought about by the collective work of a team of researchers.\nOptimization continues to grow with the help and work of\n[many people](https://github.com/qiskit-community/qiskit-optimization/graphs/contributors), who contribute\nto the project at different levels.\nIf you use Qiskit, please cite as per the provided\n[BibTeX file](https://github.com/Qiskit/qiskit/blob/main/CITATION.bib).\n\n## License\n\nThis project uses the [Apache License 2.0](https://github.com/qiskit-community/qiskit-optimization/blob/main/LICENSE.txt).\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "Qiskit Optimization: A library for optimization applications using quantum computing",
    "version": "0.6.1",
    "project_urls": {
        "Bug Tracker": "https://github.com/qiskit-community/qiskit-optimization/issues",
        "Documentation": "https://qiskit-community.github.io/qiskit-optimization/",
        "Homepage": "https://github.com/qiskit-community/qiskit-optimization",
        "Source Code": "https://github.com/qiskit-community/qiskit-optimization"
    },
    "split_keywords": [
        "qiskit",
        "sdk",
        "quantum",
        "optimization"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a7677669e6ad0b41b1e4ab79b592a4f1de748cac946169f5409e7a9f4bafef10",
                "md5": "70a15c5d1bdf0bf4de64783f596340e8",
                "sha256": "3f09f31289dfef66bbbb03b782a94d88a4ba5681c728b4b8e96884de5fc83879"
            },
            "downloads": -1,
            "filename": "qiskit_optimization-0.6.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "70a15c5d1bdf0bf4de64783f596340e8",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 167560,
            "upload_time": "2024-02-28T02:53:21",
            "upload_time_iso_8601": "2024-02-28T02:53:21.451618Z",
            "url": "https://files.pythonhosted.org/packages/a7/67/7669e6ad0b41b1e4ab79b592a4f1de748cac946169f5409e7a9f4bafef10/qiskit_optimization-0.6.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "806330ae1aa61c407ccd7f2a1499884653cf6be87fd4a216013c226273796a8f",
                "md5": "bef7547ff3ba5a216e7b06271d63daf4",
                "sha256": "0ad8c2bc83fe80657c788b5f282ce4055d0ec005c4876789e5069499ee3c00c0"
            },
            "downloads": -1,
            "filename": "qiskit-optimization-0.6.1.tar.gz",
            "has_sig": false,
            "md5_digest": "bef7547ff3ba5a216e7b06271d63daf4",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 156898,
            "upload_time": "2024-02-28T02:53:24",
            "upload_time_iso_8601": "2024-02-28T02:53:24.080531Z",
            "url": "https://files.pythonhosted.org/packages/80/63/30ae1aa61c407ccd7f2a1499884653cf6be87fd4a216013c226273796a8f/qiskit-optimization-0.6.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-28 02:53:24",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "qiskit-community",
    "github_project": "qiskit-optimization",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "qiskit",
            "specs": [
                [
                    ">=",
                    "0.44"
                ]
            ]
        },
        {
            "name": "qiskit-algorithms",
            "specs": [
                [
                    ">=",
                    "0.2.0"
                ]
            ]
        },
        {
            "name": "scipy",
            "specs": [
                [
                    ">=",
                    "1.9.0"
                ]
            ]
        },
        {
            "name": "numpy",
            "specs": [
                [
                    ">=",
                    "1.17"
                ]
            ]
        },
        {
            "name": "docplex",
            "specs": [
                [
                    ">=",
                    "2.21.207"
                ],
                [
                    "!=",
                    "2.24.231"
                ]
            ]
        },
        {
            "name": "setuptools",
            "specs": [
                [
                    ">=",
                    "40.1.0"
                ]
            ]
        },
        {
            "name": "networkx",
            "specs": [
                [
                    ">=",
                    "2.6.3"
                ]
            ]
        }
    ],
    "tox": true,
    "lcname": "qiskit-optimization"
}
        
Elapsed time: 0.19189s