"Orquestra's library with code related to variational quantum algorithms."
Project description
orquestra-vqa
What is it?
orquestra-vqa
is a library with core functionalities for implementing variational quantum algorithms developed by Zapata for our Orquestra platform.
orquestra-vqa
provides:
- interfaces for implementing ansatzes including qaoa and qcbm.
- optimizers and cost functions tailored to vqa
- misc functions such as grouping, qaoa interpolation, and estimators
Installation
Even though it's intended to be used with Orquestra, orquestra-vqa
can be also used as a Python module.
To install it you need to run pip install orquestra-vqa
or pip install .
from the main directory. This installation will install its dependencies: orquestra-quantum
, orquestra-opt
and orquestra-cirq
.
Usage
Here's an example of how to use methods from orquestra-vqa
to create a cost function for qcbm and optimize it using scipy optimizer.
from orquestra.vqa.cost_function.qcbm_cost_function import create_QCBM_cost_function
from orquestra.vqa.ansatz.qcbm import QCBMAnsatz
from orquestra.opt.history.recorder import recorder
from orquestra.quantum.symbolic_simulator import SymbolicSimulator
from orquestra.quantum.distributions import compute_mmd
from orquestra.quantum.distributions import MeasurementOutcomeDistribution
from orquestra.opt.optimizers.scipy_optimizer import ScipyOptimizer
import numpy as np
target_distribution = MeasurementOutcomeDistribution(
{
"0000": 1.0,
"0001": 0.0,
"0010": 0.0,
"0011": 1.0,
"0100": 0.0,
"0101": 1.0,
"0110": 0.0,
"0111": 0.0,
"1000": 0.0,
"1001": 0.0,
"1010": 1.0,
"1011": 0.0,
"1100": 1.0,
"1101": 0.0,
"1110": 0.0,
"1111": 1.0,
}
)
def orquestra_vqa_example_function():
ansatz = QCBMAnsatz(1, 4, "all")
backend = SymbolicSimulator()
distance_measure_kwargs = {
"distance_measure": compute_mmd,
"distance_measure_parameters": {"sigma": 1},
}
cost_function = create_QCBM_cost_function(
ansatz,
backend,
10,
**distance_measure_kwargs,
target_distribution=target_distribution
)
optimizer = ScipyOptimizer(method="L-BFGS-B")
initial_params = np.ones(ansatz.number_of_params) / 5
opt_results = optimizer.minimize(cost_function, initial_params)
return opt_results
orquestra_vqa_example_function()
Development and Contribution
You can find the development guidelines in the orquestra-quantum
repository.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file orquestra-vqa-0.6.0.tar.gz
.
File metadata
- Download URL: orquestra-vqa-0.6.0.tar.gz
- Upload date:
- Size: 79.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84fb2497f2ecf8a67dc0958aea885dda546c3abe83f5f213a8edeccf7a583ef7 |
|
MD5 | a8f73236ceea39ac84b38ad31f7c002f |
|
BLAKE2b-256 | e1d01488f33d55cb224a7185d8b81b22609155aedd233f5a2ab99eec3b46b237 |