Skip to main content

"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

orquestra-vqa-0.9.0.tar.gz (85.7 kB view details)

Uploaded Source

File details

Details for the file orquestra-vqa-0.9.0.tar.gz.

File metadata

  • Download URL: orquestra-vqa-0.9.0.tar.gz
  • Upload date:
  • Size: 85.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.11

File hashes

Hashes for orquestra-vqa-0.9.0.tar.gz
Algorithm Hash digest
SHA256 cda1ba38c64d033e82abdde250e02ea047547df4b05cc3a6e84d64c313ec3a8b
MD5 c27793522c9d1cb08743a8ff5848c6ea
BLAKE2b-256 f4bc494119b86b9da92da19be9fee3acacf2195e875cb42dd8ec0afb86c590cf

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page