Coder Social home page Coder Social logo

optimization's Introduction

Quantum Approximate Optimization Algorithm for Portfolio Optimization Problem

This is a repository for Portfolio Optimization Problem that use Python code to generate their results (though it can be adapted to other applications).

Software implementation

All source code used to generate the results and figures in the project are in the root directory. Specifically, portfolio_optimization.py is used to load and pre-process the portfolio data, which can be obtained in /data folder. Running the code in qaoa.py generates the results in our project report, where the QAOA circuit is constructed using Pyqpanda framework and the parameter optimization is implemented by the optimizer from Scipy or Qiskit. In order to offer a benchmark for our experiment, we construct a Python Script qaoa_qiskit.py with the identical function using Qiskit exclusively. The figure generation is all run inside plot_result.py. Results generated by the code are saved in /out.

Getting the code

You can download a copy of all the files in this repository by cloning the git repository:

git clone https://github.com/abel1231/optimization.git

or download a zip archive.

Dependencies

You'll need a working Python environment to run the code. All the experiments we have done are run in the conda virtual environment with Python 3.8.

To build and test the software, produce all results and figures, run this in the top level of the repository:

pip install -r requirements.txt

If all goes well, all dependencies will be installed successfully.

Examples of how to use the code

To obtain the optimal solution of the quadratic optimization problem produced by the classical optimization method, run

python portfolio_optimization.py

To train an 8-layer QAOA model under the setting of 4 budget, 6 assets, 2 bits for representing one asset, and we set the maximum number of optimization iterations to 2000, run the code

python qaoa.py --budget 4 --num_assets 6 --g 2 --layers 8 --maxiter 2000

Running python qaoa.py --help for more information about options.

The results of the training will be printed out in shell, and we give some results in the /out folder.

Or you can use the same parameter configuration to run the QAOA model based on Qiskit

python qaoa_qiskit.py --budget 4 --num_assets 6 --g 2 --layers 8 --maxiter 2000

Running python qaoa_qiskit.py --help for more information about options.

The default optimizer is COBYLA from Qiskit, as we empirically observe that it has a more efficient optimization process and guarantees the optimization performance. Note that you can replace it with any other optimizers from either Scipy Methods, or Qiskit Optimizers.

In order to generate the figures that characterize the probability distribution of the final quantum state relative to the Hamiltonian, we provide plot_result.py. For example,

python plot_result.py --num_diaplay 5 --offset 0.0001 --path ./out/b2_g1_ly8.out

optimization's People

Contributors

abel1231 avatar xiaotailong avatar xinyuyee avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

xinyuyee

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.