-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #400 from Quantum-TII/simtfrename
refactoring for qibotf
- Loading branch information
Showing
40 changed files
with
423 additions
and
324 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../examples/falqon/README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../examples/falqon/images/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Feedback-based ALgorithm for Quantum OptimizatioN - FALQON | ||
|
||
Code at: [https://github.com/Quantum-TII/qibo/tree/master/examples/falqon](https://github.com/Quantum-TII/qibo/tree/master/examples/falqon) | ||
|
||
Quantum Approximate Optimisation Algorithm (QAOA) is considered as one of the most important algorithms for optimisation in Quantum Computers, see [arXiv:1411.4028](https://arxiv.org/abs/1411.4028) by Farhi, Goldstone and Gutmann for more information. | ||
|
||
In this QAOA algorithm, the aim is to have a problem Hamiltonian H_P and a mixer Hamiltonian H_B. Then, starting with the ground state of H_B, the goal is to repeatedly apply e^(i H_P c) and e^(i H_B b), where c and b are tunable parameters. The values of such parameters are to be found via classical optimization | ||
|
||
In the FALQON algorithm, [arXiv:2103.08619](https://arxiv.org/abs/2103.08619) by Magann, Rudinger, Grace and Sarovan, they propose a similar although conceptually different algorithm. The proposal consists in evolving the initial state using the Schrödinger equation | ||
|
||
![schrodingerequation](images/schrodinger_equation.png) | ||
|
||
This equation satisfies that the expectation value of H_P is monotonically decreasing. This feature is used to create a Hamiltonian evolution with 1 layer using e^(i H_P c) and e^(i H_B b). In the first layer, b=0, and c is a parameter to be defined. Then, the quantity A = i[H_P, H_B] is measured. Its expectation value is then taken to be the parameter b for the next layer. As more layers are added, the | ||
approximation to the ground state of the problem Hamiltonian H_P is more and more accurate. | ||
|
||
![scheme](images/scheme.png) | ||
|
||
### Running the code | ||
|
||
This example contains just one file | ||
- `main.py` is the file where the algorithm is run. The main class `FALQON` is now introduced in `QIBO` | ||
|
||
The `FALQON` class behaves similarly to the `QAOA` one. It admits the following parameters: | ||
- `hamiltonian`: problem Hamiltonian | ||
whose ground state is sought. | ||
- `mixer`: mixer Hamiltonian. | ||
If ``None``, `qibo.hamiltonians.X` is used. | ||
- `solver`: solver used to apply the exponential operators. | ||
Default solver is 'exp'. | ||
- `callbacks`: List of callbacks to calculate during evolution. | ||
- `accelerators`: Dictionary of devices to use for distributed | ||
execution. See `qibo.tensorflow.distcircuit.DistributedCircuit` | ||
for more details. This option is available only when ``hamiltonian`` | ||
is a `qibo.abstractions.hamiltonians.TrotterHamiltonian`. | ||
- `memory_device`: Name of device where the full state will be saved. | ||
Relevant only for distributed execution (when ``accelerators`` is | ||
given). | ||
|
||
When performing the execution of the problem, the following variables are to be set: | ||
|
||
- `delta_t`: initial guess for the time step. A too large delta_t will make the algorithm fail. | ||
- `max_layers`: maximum number of layers allowed for the FALQON. | ||
- `initial_state`: initial state vector of the FALQON. | ||
- `tol`: Tolerance of energy change. If not specified, no check is done. | ||
- `callback`: Called after each iteration for scipy optimizers. | ||
- `options`: a dictionary with options for the different optimizers. | ||
- `compile`: whether the TensorFlow graph should be compiled. | ||
- `processes`: number of processes when using the paralle BFGS method. | ||
|
||
The attached example provides an easy implementation of the FALQON method for a Heisenberg XXZ model. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import argparse | ||
from qibo import models, hamiltonians | ||
|
||
|
||
def main(nqubits, delta_t=.1, max_layers=100): | ||
# create XXZ Hamiltonian for nqubits qubits | ||
hamiltonian = hamiltonians.XXZ(nqubits) | ||
# create FALQON model for this Hamiltonian | ||
falqon = models.FALQON(hamiltonian) | ||
|
||
best_energy, final_parameters = falqon.minimize(delta_t, max_layers)[:2] | ||
|
||
print('The optimal energy found is', best_energy) | ||
|
||
return best_energy, final_parameters | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--nqubits", default=5, type=int, help="Number of qubits.") | ||
parser.add_argument("--delta_t", default=.1, type=float, help="Optimization parameter, time step for the first layer") | ||
parser.add_argument("--max_layers", default=100, type=int, help="Maximum number of layers") | ||
args = vars(parser.parse_args()) | ||
main(**args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
# Runtime requirements for qibo | ||
|
||
# numpy (included in tf) | ||
tensorflow==2.4.1 | ||
scipy | ||
sympy | ||
cma | ||
|
Oops, something went wrong.