Skip to main content

Qruise Calibrate Remote API

A client library for runnig a control optimization with qruise calibrate software

Note

The API is experimental and subject to change without a prior notice

Description

The qcalibrateremote package provides interface to QCalibrate optimization service, providing algorithms helping to define optimal control for quantum system. The actual optimization algorithm runs on the server, supplying the set of parameters and/or PWC pulses to client side. The client code evaluates the parameters by deriving and applying control signals to a system under control, performing measurement, calcualates and returns the figure of merit (infidelity) value. The algorithm tries different parameters in order to find optimal values to achieve minimal infidelity. Live progress of optimization can be observed in the in web UI, given opportunity to finish the optimization, before the optimization stopping criteria are achieved.

Currently two optimization modes are supported.

  • pure parameter optimization

  • Random chopped base PWC function optimization (Fourier and Sigmoid bases)

Installing

Install with pip:

$ pip install qcalibrateremote

for conda environment install grcpio explicitly

$ conda install grpcio

Usage

Prerequisits

  • Python 3.8+ (developed and tested with 3.8.5)

  • Qruise Calibrate account (contact r.razilov@fz-juelich.de for details)

  • Direct internet connection to server (may require VPN access)

Experiment

Experiment defines is a set of meta-parameters controlling the optimization Use use API or Web UI to create an experiment and define optimization parameters. Use online help to get learn about details. The evaluation of figure of merit class can be supplied as class evaluate_fom_class=.. or object evaluate_fom_object=..

Pure parameter optimization example

# import dependencies
from typing import Dict

from qcalibrateremote import (
    EvaluateFigureOfMerit,
    FigureOfMerit,
    create_optimizer_client,
)

# setup client connection (copy form web UI: https://www.qcalibrate.staging.optimal-control.net:31603)
experiment_id="0xabcd"
token=("ey...")

optimizer_client = create_optimizer_client(
    host="grpc.qcalibrate.staging.optimal-control.net", port=31603, token=token)

# define infidelity evaluation class
class DistanceFom(EvaluateFigureOfMerit):

    def __init__(self, *args, **kwargs) -> None:
        super().__init__()

    def infidelity(self, param1, param2) -> float:
        return (param1 - 0.55)**2 + (param2 - 0.33)**2

    def evaluate(self, parameters: Dict[str, float], **kwargs) -> FigureOfMerit:
        """Abstract method for figure of merit evaluation"""
        # print(parameters)
        return FigureOfMerit(self.infidelity(**parameters), '')

# run optimization
optimization_result = optimizer_client.run(experiment_id=experiment_id, evaluate_fom_class=DistanceFom)

# best fitting parameters
optimization_result.top[0].parameters

Rather than create a completely new configuration, one can update an existing experiment configuration

with optimizer_client.update_experiment(experiment_id) as experiment_builder:
    with experiment_builder.configuration() as configuration:
        with configuration.parameter("param1") as param1:
            param1.initial_value = 0.7


optimization_result = optimizer_client.run(
    experiment_id=experiment_id, evaluate_fom_class=DistanceFom)

# best fitting parameters
optimization_result.top[0].parameters

Pulse optimization example

# import dependencies
from typing import Dict

from qcalibrateremote import (
    EvaluateFigureOfMerit,
    FigureOfMerit,
    create_optimizer_client,
    Pulse,
)

# setup client connection (copy form web UI: https://www.qcalibrate.staging.optimal-control.net:31603)
token=("ey...")

optimizer_client = create_optimizer_client(
    host="grpc.qcalibrate.staging.optimal-control.net", port=31603, token=token)

experiment_builder = optimizer_client.create_pulse_optimization_experiment("Pulse optimization", "Created by " + __file__)

# define configuration

with experiment_builder.configuration() as configuration:

    with configuration.time("time1") as time1:
        time1.initial_value = 1
        time1.optimize = False

    with configuration.pulse("pulse1") as pulse1:
        pulse1.time_name = "time1"
        pulse1.lower_limit = -1
        pulse1.upper_limit = 1
        pulse1.bins_number = 21
        with pulse1.fourier_basis() as fourier_basis:
            fourier_basis.basis_vector_number = 5
            with fourier_basis.uniform_super_parameter_distribution() as uniform_super_parameter_distribution:
                uniform_super_parameter_distribution.lower_limit = 0.01
                uniform_super_parameter_distribution.upper_limit = 5

        with pulse1.initial_guess() as initial_guess:
            initial_guess.function = "lambda t: 1"
        with pulse1.scaling_function() as scaling_function:
            scaling_function.function = "lambda t: np.exp(-(t - 0.5)**2/(2*0.2**2))"

    with configuration.dcrab_settings() as dcrab_settings:
        dcrab_settings.maximum_iterations_per_super_iteration = 50
        dcrab_settings.super_iteration_number = 6

experiment_id = optimizer_client.add_experiment(experiment_builder)

# define infidelity evaluation class
def expected_pulse(t):
    return np.sin(2*np.pi*t)**4

class SineFom(EvaluateFigureOfMerit):

    def evaluate(self, parameters: Dict[str, float], pulses: Dict[str, Pulse], **kwargs) -> FigureOfMerit:
        pulse1 = pulses["pulse1"]

        inf = np.sum((expected_pulse(pulse1.times) - pulse1.values)**2)

        return FigureOfMerit(inf, '{}')

# run optimization
optimization_result = optimizer_client.run(experiment_id=experiment_id, evaluate_fom_object=SineFom())

# plot best fitting pulse
pulse1 = optimization_result.top[0].pulses["pulse1"]
import matplotlib.pyplot as plt

plt.plot(pulse1.times, expected_pulse(pulse1.times))
plt.plot(pulse1.times, pulse1.values)

Metadata

Release files for qcalibrateremote 0.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for qcalibrateremote 0.2.3
File Size Uploaded Provenance Actions
qcalibrateremote-0.2.3.tar.gz 2.1 MB Without provenance Details for qcalibrateremote-0.2.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for qcalibrateremote 0.2.3
File Interpreter ABI Platform Actions
qcalibrateremote-0.2.3-py2.py3-none-any.whl Python 2, Python 3 none any Details for qcalibrateremote-0.2.3-py2.py3-none-any.whl

Total release size: 2.2 MB

Release files / qcalibrateremote-0.2.3.tar.gz

Download URL qcalibrateremote-0.2.3.tar.gz
Size 2.1 MB
Tags Source
SHA-256 checksum
How to use checksums
3f12ab8634ac79f259f41e13f7bb41c3fb2da4bf50d87d90ab69bbee812bd40a
BLAKE2b-256 checksum
How to use checksums
81f891a7b53be61ff30c908f29db16b3f4f6dda1a771478543d82d6164dc8879
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.5

Release files / qcalibrateremote-0.2.3-py2.py3-none-any.whl

Download URL qcalibrateremote-0.2.3-py2.py3-none-any.whl
Size 36.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
5e86e73e818fa22edc6314de97ccc6a55628846c7e927d98b5b4e7e00f505b4b
BLAKE2b-256 checksum
How to use checksums
f6c5546341976679bd9604a5ddeaddaceab3b8d2cef99f3dc08f21209248f47a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.5

Security for qcalibrateremote 0.2.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page