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

remove parser #92

Merged
merged 27 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
52c6bcd
remove parser
Edoardo-Pedicillo Oct 16, 2024
401d1aa
expose DBI type
Edoardo-Pedicillo Oct 16, 2024
3290e09
use nlayers
Edoardo-Pedicillo Oct 16, 2024
94c1420
move main.py in src/boostvqe/boost.py and update the README
Edoardo-Pedicillo Oct 16, 2024
8bd5c91
typo in README
Edoardo-Pedicillo Oct 16, 2024
8ea85f0
clean code
Edoardo-Pedicillo Oct 16, 2024
4ab779c
README installation instructions
Edoardo-Pedicillo Oct 16, 2024
ed50b14
README installation instructions
Edoardo-Pedicillo Oct 16, 2024
5744c7a
update pyproject
Edoardo-Pedicillo Oct 16, 2024
9c54a48
remove help from the README script
Edoardo-Pedicillo Oct 16, 2024
e9b12b1
rename main function dbi_vqe
Edoardo-Pedicillo Oct 16, 2024
f70b447
remove -e option in README
Edoardo-Pedicillo Oct 16, 2024
18f97dd
increase example readibility
Edoardo-Pedicillo Oct 16, 2024
79cf18b
Update src/boostvqe/boost.py
Edoardo-Pedicillo Oct 16, 2024
c581583
fix: remove optimize_dbi_step
Edoardo-Pedicillo Oct 22, 2024
102b2ab
Merge branch 'simplify_main' of github.com:qiboteam/boostvqe into sim…
Edoardo-Pedicillo Oct 22, 2024
8c0db95
feat: some fixes to Edo's improvments
MatteoRobbiati Nov 5, 2024
c168558
feat: add script to run vqe training
MatteoRobbiati Nov 5, 2024
ad3f398
fix: RBS derivative
MatteoRobbiati Nov 6, 2024
7e1c1db
Merge pull request #99 from qiboteam/training_fixes
MatteoRobbiati Nov 11, 2024
981f103
Update src/boostvqe/boost.py
Edoardo-Pedicillo Nov 12, 2024
e35f336
refactor: use time_steps
Edoardo-Pedicillo Nov 13, 2024
52339e5
refactor: rename dbi_steps in dbqa_steps
Edoardo-Pedicillo Nov 13, 2024
aee638a
refactor: rename time)steps in dbr_duration
Edoardo-Pedicillo Nov 13, 2024
33050cb
docs: change dbqa_steps description
Edoardo-Pedicillo Nov 13, 2024
5301e45
fix: boost.py working
andrea-pasquale Nov 29, 2024
e122902
Merge branch 'main' into simplify_main
Edoardo-Pedicillo Dec 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ Boosting variational eigenstate preparation algorithms limited by training and n
The package can be installed by source after cloning the repository:

```sh
pip install -e .
cd boostvqe
Edoardo-Pedicillo marked this conversation as resolved.
Show resolved Hide resolved
pip install .
```

will install `boostvqe 0.0.1` and activate a dedicated working shell.

## Code structure

The file `main.py` performs boosted VQE training.
The file `src/boostvqe/boost.py` performs boosted VQE training.

The source code is located in `./src/boostvqe/.` and its composed of:

Expand All @@ -24,14 +23,24 @@ The source code is located in `./src/boostvqe/.` and its composed of:
* `plotscripts.py`: plotting functions.
* `compiling_XXZ.py`: compilation for XXZ model.

## How to run the code
## Example

For further information about the inputs:
It follows a python snippet explaining how to run the boosting

```sh
python main.py --help
```py

from boostvqe.boost import dbqa_vqe
from boostvqe.ansatze import hdw_efficient

from qibo.models.dbi.double_bracket import DoubleBracketGeneratorType

circuit = hdw_efficient(nqubits=2, nlayers=2)
output_folder = "output"
dbqa_vqe(circuit, output_folder, mode = DoubleBracketGeneratorType.group_commutator)
```
marekgluza marked this conversation as resolved.
Show resolved Hide resolved

All the info regarding `dbqa_vqe` can be generated with `help(dbqa_vqe)`.

# Tutorials

Some useful notebooks to understand how the library works, are collected [here](notebooks/notebooks_links.md).
Expand Down
2,264 changes: 2,261 additions & 3 deletions poetry.lock

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ readme = "README.md"
packages = [{ include = "boostvqe", from = "src" }]

[tool.poetry.dependencies]
python = "^3.9"
python = ">=3.9,<3.13"
numpy = "^1.26.4"
numba = "^0.59.0"
qibo = "^0.2.12"
tensorflow = "^2.17.0"
matplotlib = "^3.9.2"
seaborn = "^0.13.2"
hyperopt = "^0.2.7"
qibojit = "^0.1.6"

[tool.poetry.group.dev.dependencies]
ipython = "^7.34"
Expand Down
36 changes: 19 additions & 17 deletions src/boostvqe/ansatze.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@

from boostvqe.training_utils import vqe_loss


def connect_qubits(circuit, jumpsize=1, start_from=0):
def get_circular_index(n, index):
circular_index = index % n
return circular_index
for q in range(start_from, circuit.nqubits, jumpsize+1):

for q in range(start_from, circuit.nqubits, jumpsize + 1):
ctrl_index = q
targ_index = get_circular_index(circuit.nqubits, q+jumpsize)
circuit.add(gates.RBS(q0=ctrl_index, q1=targ_index, theta=0.))
targ_index = get_circular_index(circuit.nqubits, q + jumpsize)
circuit.add(gates.RBS(q0=ctrl_index, q1=targ_index, theta=0.0))
return circuit


Expand All @@ -31,18 +33,16 @@ def hdw_efficient(nqubits, nlayers):
circuit.add(gates.RY(q, theta=0) for q in range(nqubits))

return circuit


def hw_preserving(nqubits, nlayers=1):

if nqubits%2 != 0:
def hw_preserving(nqubits, nlayers=1):
if nqubits % 2 != 0:
raise_error(
ValueError,
"To use this ansatz please be sure number of qubits is even."
)
ValueError, "To use this ansatz please be sure number of qubits is even."
)
c = Circuit(nqubits)

for q in range(int(nqubits/2)):
for q in range(int(nqubits / 2)):
c.add(gates.X(q))

for _ in range(int(nlayers)):
Expand All @@ -54,28 +54,30 @@ def hw_preserving(nqubits, nlayers=1):

return c


def su2_preserving(nqubits, nlayers):
"""SU2 invariant circuit."""
c = Circuit(nqubits)
for _ in range(nlayers):
for q in range(1, nqubits, 2):
c.add(gates.RXX(q0=q, q1=(q+1)%nqubits, theta=0.))
c.add(gates.RYY(q0=q, q1=(q+1)%nqubits, theta=0.))
c.add(gates.RZZ(q0=q, q1=(q+1)%nqubits, theta=0.))
c.add(gates.RXX(q0=q, q1=(q + 1) % nqubits, theta=0.0))
c.add(gates.RYY(q0=q, q1=(q + 1) % nqubits, theta=0.0))
c.add(gates.RZZ(q0=q, q1=(q + 1) % nqubits, theta=0.0))
for q in range(0, nqubits, 2):
c.add(gates.RXX(q0=q, q1=(q+1)%nqubits, theta=0.))
c.add(gates.RYY(q0=q, q1=(q+1)%nqubits, theta=0.))
c.add(gates.RZZ(q0=q, q1=(q+1)%nqubits, theta=0.))
c.add(gates.RXX(q0=q, q1=(q + 1) % nqubits, theta=0.0))
c.add(gates.RYY(q0=q, q1=(q + 1) % nqubits, theta=0.0))
c.add(gates.RZZ(q0=q, q1=(q + 1) % nqubits, theta=0.0))
return c


def compute_gradients(parameters, circuit, hamiltonian):
"""
Compute gradients of circuit's parameters to check the problem trainability.
The evaluated derivatives are the ones of the expectation of `hamiltonian`
over the final state get running `circuit.execute` w.r.t. rotational angles.

"""
tf_backend = construct_backend("tensorflow")
tf_backend = construct_backend(backend="qiboml", platform="tensorflow")
parameters = tf_backend.tf.Variable(parameters, dtype=tf_backend.tf.float64)

with tf_backend.tf.GradientTape() as tape:
Expand Down
Loading