Welcome to EntropicaQAOA¶
EntropicaQAOA is a modular package for the quantum approximate optimisation algorithm (QAOA) built on top of Rigetti’s Forest SDK.
Multiple built-in parametrisations for QAOA, which facilitate prototyping and testing of different approaches to solving a problem.
Convenient optimiser logging tools.
Ability to run more general parametric circuits using the VQE library.
Full native support for Rigetti’s QVM and QPUs. Run your experiments on real Quantum Computers!
Modular code base that allows the user to customise and modify different components: use your favourite classical optimisation library, or write your own parameter class.
Extensive examples explaining the usage of EntropicaQAOA in detail.
If you don’t have them already, you should first install Rigetti’s pyQuil package, as well as their QVM and Quil Compiler. For instructions on how to do so, see Rigetti’s documentation here.
You can install EntropicaQAOA using pip:
pip install entropica-qaoa
To upgrade to the latest version:
pip install --upgrade entropica-qaoa
If you want to run the Demo Notebooks, you will additionally need to install scikit-learn and scikit-optimize:
pip install scikit-learn && pip install scikit-optimize
You can also install EntropicaQAOA directly from GitHub. In your desired local directory, first clone the repository
git clone https://github.com/entropicalabs/entropica_qaoa.git
then move into the
entropica_qaoa directory, and run pip:
cd entropica-qaoa pip install -e
Testing the installation¶
Run the following short code to verify that EntropicaQAOA has been successfully installed. Here, we create a simple Hamiltonian
and evaluate its expectation value with respect to the wavefunction produced by a QAOA circuit. We choose the
and initialise the parameter values by analogy to a quantum annealing process with a linear schedule function. These features are explained in depth in other sections of
Before running the code, make sure you open the Rigetti QVM and Quil compiler in separate terminal windows using the commands
qvm -S and
# pyquil imports from pyquil import Program from pyquil.api import WavefunctionSimulator from pyquil.paulis import PauliSum, PauliTerm # EntropicaQAOA imports from entropica_qaoa.qaoa.parameters import StandardParams from entropica_qaoa.qaoa.cost_function import QAOACostFunctionOnWFSim # create a hamiltonian on 3 qubits with 2 coupling terms and 1 bias term Term1 = PauliTerm("Z", 0, 0.7)*PauliTerm("Z", 1) Term2 = PauliTerm("Z", 0, 1.2)*PauliTerm("Z", 2) Term3 = PauliTerm("Z", 0, -0.5) ham = PauliSum([Term1,Term2,Term3]) p = 3 # QAOA p parameter (number of timesteps) params = StandardParams.linear_ramp_from_hamiltonian(ham,p) # initialise a set of StandardParams # Build the cost function and compute its value with the circuit parameters initialised above cost_fun = QAOACostFunctionOnWFSim(ham,params) res = cost_fun(params.raw()) print(res)
You should find the value of
res to be -1.4664694.
If you installed directly from GitHub, you can also run the full set of software tests. To do so, you will need to install pytest. To speed up the testing, we have tagged tests that require more computational time (~ 5 mins or so) with runslow, and the tests of the notebooks with notebooks. The commands are as follows:
pytestruns the default tests, and skips both the longer tests that need heavier simulations, as well as tests of the Notebooks in the
pytest --runslowruns the the tests that require longer time.
pytest --notebooksruns the Notebook tests. To achieve this, the notebooks are converted to python scripts, and then executed. Should any errors occur, this means that the line numbers given in the error messages refer to the lines in <TheNotebook>.py, and not in <TheNotebook>.ipynb.
pytest --allruns all of the above tests.
Note that the Quil compiler and QVM need to be running for all of the tests to pass successfully.
The tutorials in this documentation can also downloaded as Jupyter notebooks from our GitHub page .
Contributing and feedback¶
If you find any bugs or errors, have feature requests, or code you would like to contribute, feel free to open an issue or send us a pull request on GitHub .
We are always interested to hear about projects built with EntropicaQAOA. If you have an application you’d like to tell us about, drop us an email at firstname.lastname@example.org.
EntropicaQAOA is released open source under the Apache License, Version 2.0.
- Overview of tutorials
- First steps: An example workflow
- Working with the Parameter classes
- Creating the problem Hamiltonian and setting up hyperparameters
- QAOA variable parameter classes
- Parameter creation and conversion routines
- Working with parametrisations
- Advanced QAOA parameter classes
- Cost function features and VQE
- Short Intro: The Variational Quantum Eigensolver (VQE)
- Setting up the problem
- Simulating sampling noise
- Getting the measurement variance
- Logging of the optimisation process
- Running on the QVM or QPU
- Using other optimisers
- Towards QAOA
- Appendix: Simulated measurement noise - statistics implementation details
- Utility functions for QAOA
- Hamiltonians and graphs
- Hamiltonians and data
- Example 1: Using QAOA to solve MaxCut for the clustering problem
- Example 2: The Ring of Disagrees
- More miscellaneous utilities
- Solving a simple QUBO with QAOA
- Solve the clustering problem using QAOA
- VQE cost functions
- QAOA cost functions
- QAOA Parametrisations
- VQE and QAOA utilities
- Measurement utilities