Skip to main content

No project description provided

Project description

Q-Alchemy Python SDK

This is the Python-SDK for using the data cybernetics Q-Alchemy API which helps quantum computing researchers to put classical data into the quantum computer. This is all also called: the loading problem, encoding problem, or quantum state preparation. Some people also call it a form of QRAM, or quantum random-access memory.

This SDK builds upon the Hypermedia-Siren API of data cybernetics which uses a document-first approach added with actions. The standardized way makes the API programmatically accessible, which can be explored by the Hypermedia-Test-UI

The SDK builds upon this, so that any software developer planning to integrate with the API and experience the API through the UI and the SDK in a very similar fashion. Also, any GUI around this has similar characteristics.

Installation

We have decided not to go through pypi, but you can install this through pip or poetry nonetheless

pip install q-alchemy-sdk-py

If you want to use the qiskit-integration, please use

pip install q-alchemy-sdk-py[qiskit]

And if you want the PennyLane-integration, please use

pip install q-alchemy-sdk-py[pennylane]

We use python-pdm and have tested this all with Python 3.11 or higher (but less than 4!). So the way to install it after cloning is simply

pdm install

Again, for qiskit- or PennyLane-integrations, please add the groups

pdm install -G qiskit -G pennylane

Or whatever combination you need. Currently, the PennyLane-integration is dependent on the qiskit-integration... what a fallacy! We will -- of course -- fix this soon!

Usage

There are examples under the /examples folder, but for those that are eager to find out, here it is. First, you will want to get an API key from the Q-Alchemy Portal. You need to sign up for this, sorry, but this is necessary. Once you have the API key (free of charge of course) you can test it!

Direct Example

import numpy as np
from sklearn.datasets import fetch_openml

from q_alchemy.initialize import q_alchemy_as_qasm

mnist = fetch_openml('mnist_784', version=1, parser="auto")

zero: np.ndarray = mnist.data[mnist.target == "0"].iloc[0].to_numpy()
filler = np.empty(2 ** 10 - zero.shape[0])
filler.fill(0)

zero = np.hstack([zero, filler])
zero = zero / np.linalg.norm(zero)

qasm, summary = q_alchemy_as_qasm(zero, max_fidelity_loss=0.2, api_key="<your api key>", return_summary=True)
print(summary)

Qiskit Example

import numpy as np
from sklearn.datasets import fetch_openml

from q_alchemy.qiskit_integration import QAlchemyInitialize, OptParams

mnist = fetch_openml('mnist_784', version=1, parser="auto")

zero: np.ndarray = mnist.data[mnist.target == "0"].iloc[0].to_numpy()
filler = np.empty(2 ** 10 - zero.shape[0])
filler.fill(0)

zero = np.hstack([zero, filler])
zero = zero / np.linalg.norm(zero)

instr = QAlchemyInitialize(
    params=zero.tolist(),
    opt_params=OptParams(
        max_fidelity_loss=0.1,
        basis_gates=["id", "rx", "ry", "rz", "cx"],
        api_key="<your api key>"
    )
)
instr.definition.draw(fold=-1)

PennyLane Example

import numpy as np
import pennylane as qml
from sklearn.datasets import fetch_openml

from q_alchemy.pennylane_integration import QAlchemyStatePreparation, OptParams

mnist = fetch_openml('mnist_784', version=1, parser="auto")

zero: np.ndarray = mnist.data[mnist.target == "0"].iloc[0].to_numpy()
filler = np.empty(2 ** 10 - zero.shape[0])
filler.fill(0)

zero = np.hstack([zero, filler])
zero = zero / np.linalg.norm(zero)

dev = qml.device('lightning.qubit', wires=10)

@qml.qnode(dev)
def circuit(state=None):
    QAlchemyStatePreparation(
        state,
        wires=range(10),
        opt_params=OptParams(
            max_fidelity_loss=0.1,
            basis_gates=["id", "rx", "ry", "rz", "cx"],
            api_key="<your api key>"
        )
    )
    return qml.state()

print(qml.draw(circuit, level="device", max_length=100)(zero.tolist()))

Developer UI

You can play around with this as you please and check out the Hypermedia-Test-UI for more info!

Contributions

We welcome contributions - simply fork the repository of this plugin, and then make a pull request containing your contribution. All contributers to this plugin will be listed as authors on the releases.

We also encourage bug reports, suggestions for new features and enhancements!

Authors

Carsten Blank

License

The q-alchemy-sdk-py is free and open source, released under the Apache License, Version 2.0.

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

q_alchemy_sdk_py-0.2.16.tar.gz (44.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

q_alchemy_sdk_py-0.2.16-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

Details for the file q_alchemy_sdk_py-0.2.16.tar.gz.

File metadata

  • Download URL: q_alchemy_sdk_py-0.2.16.tar.gz
  • Upload date:
  • Size: 44.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.22.4 CPython/3.11.9 Windows/10

File hashes

Hashes for q_alchemy_sdk_py-0.2.16.tar.gz
Algorithm Hash digest
SHA256 ae189e47c68e1389ee893d343f18355d3b36e0b25702125222711cd37182fa23
MD5 99623c639f50cbc34a2b4ef736adc535
BLAKE2b-256 255a1ee94f45b6447487319bd765746f8adb4c9e0cf2d4cb63160c7c213dd346

See more details on using hashes here.

File details

Details for the file q_alchemy_sdk_py-0.2.16-py3-none-any.whl.

File metadata

  • Download URL: q_alchemy_sdk_py-0.2.16-py3-none-any.whl
  • Upload date:
  • Size: 15.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.22.4 CPython/3.11.9 Windows/10

File hashes

Hashes for q_alchemy_sdk_py-0.2.16-py3-none-any.whl
Algorithm Hash digest
SHA256 ae6347038a9c07e4d02c526b4224e504cc958b4c62b2c0a38d7e590a359cb0c4
MD5 15b8644132429635f1d7d440eec83dbf
BLAKE2b-256 f0aade9f565b0ce07d4b4882a1504d41e00cc2ba021ec4c18905eb0a0b27007b

See more details on using hashes here.

Supported by

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