Skip to main content

Cqlib Adapter

Installation

Install the package using pip:

pip install cqlib-adapter

1. Qiskit Ext

This project provides a Qiskit adapter for the TianYan quantum computing platform. It includes custom quantum gates and integrates with the TianYan backend to enable seamless execution of quantum circuits.

Features

  • Custom Quantum Gates: Adds custom gates like X2P, X2M, Y2P, Y2M, XY2P, and XY2M to Qiskit.
  • TianYan Backend Integration: Supports execution of quantum circuits on TianYan quantum computers and simulators.
  • Transpilation: Automatically transpiles Qiskit circuits to be compatible with TianYan backends.

QCIS Gates

QCIS Instruction Manual

The following QCIS gates are added to Qiskit:

  • X2P: Positive X rotation by π/2.
  • X2M: Negative X rotation by π/2.
  • Y2P: Positive Y rotation by π/2.
  • Y2M: Negative Y rotation by π/2.
  • XY2P: Positive XY rotation by a parameterized angle.
  • XY2M: Negative XY rotation by a parameterized angle.

Usage Example

Log in to the TianYan Lab, retrieve your Connection Key from the Dashboard page, and replace your_token in the code below.

from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister
from cqlib_adapter.qiskit_ext import X2PGate

# Create a quantum circuit
qs = QuantumRegister(2)
cs = ClassicalRegister(2)
circuit = QuantumCircuit(qs, cs)
circuit.x(qs[1])
circuit.h(qs[0])
circuit.cx(qs[0], qs[1])
circuit.append(X2PGate(), [qs[0]])
circuit.barrier(qs)
circuit.measure(qs, cs)

circuit.draw()

Circuit Text Diagram:

      ┌───┐     ┌─────┐ ░ ┌─┐   
q0_0: ┤ H ├──■──┤ X2p ├─░─┤M├───
      ├───┤┌─┴─┐└─────┘ ░ └╥┘┌─┐
q0_1: ┤ X ├┤ X ├────────░──╫─┤M├
      └───┘└───┘        ░  ║ └╥┘
c0: 2/═════════════════════╩══╩═
                           0  1 

1. Backend mode

from cqlib_adapter.qiskit_ext import TianYanProvider

# Initialize the TianYan provider
provider = TianYanProvider(token='your_token')

# Retrieve a specific backend (e.g., 'tianyan176-2')
backend = provider.backend('tianyan176-2')

# Run the circuit on the backend
job = backend.run([circuit], shots=3000)

# Retrieve and print the results
print(f'Job ID: {job.job_id()}')
print(f'Job Result: {job.result().get_counts()}')

2. Sampler mode

from cqlib_adapter.qiskit_ext import TianYanProvider, TianYanSampler

# Initialize the TianYan provider
provider = TianYanProvider(token='your_token')

# Retrieve a specific backend (e.g., 'tianyan24')
backend = provider.backend('tianyan24')

# Run the circuit on the backend
job = TianYanSampler(backend=backend).run([circuit], shots=3000)

# Retrieve and print the results
print(f'Job ID: {job.job_id()}')
print(f'Job Result: {job.result()}')
# c0 is the default register name
# cs = ClassicalRegister(2)
print(f'Counts: {job.result()[0].data.c0.get_counts()}')

PennyLane Ext

This project provides a PennyLane device adapter for the CQLib quantum computing framework. It enables seamless execution of PennyLane quantum circuits on various CQLib backends, including TianYan quantum hardware and simulators.

Features

  • Multiple Backend Support: Supports execution on TianYan quantum hardware, cloud simulators, and local simulators
  • Unified Interface: No need to call cqlib directly - all configuration is done through PennyLane device settings

Supported TianYan Backends

Quantum Hardware

tianyan24, tianyan504, tianyan176-2, tianyan176

Cloud Simulators

tianyan_sw, tianyan_s, tianyan_tn, tianyan_tnn, tianyan_sa, tianyan_swn

Local Simulator

default (local simulator)

Usage Example

import pennylane as qml
from pennylane import numpy as np

TOKEN = "your_token"
dev = qml.device('cqlib.device', wires=2, shots=500, cqlib_backend_name="default",login_key = TOKEN)


@qml.qnode(dev, diff_method="parameter-shift")
def circuit(params):
    qml.RX(params[0], wires=0)
    qml.RY(params[1], wires=1)
    qml.CNOT(wires=[0, 1])
    return qml.expval(qml.PauliY(0))
params = np.array([0.5, 0.8], requires_grad=True)

opt = qml.GradientDescentOptimizer(stepsize=0.1)
steps = 10
for i in range(steps):
    params = opt.step(circuit, params)

    print(f"step {i + 1}: paras = {params}, exps = {circuit(params)}")

License

This project is licensed under the Apache License, Version 2.0. See the LICENSE file for details.

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.

Metadata

Release files for cqlib-adapter 0.3.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 cqlib-adapter 0.3.3
File Size Uploaded Provenance Actions
cqlib_adapter-0.3.3.tar.gz 40.6 kB Without provenance Details for cqlib_adapter-0.3.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cqlib-adapter 0.3.3
File Interpreter ABI Platform Actions
cqlib_adapter-0.3.3-py3-none-any.whl Python 3 none any Details for cqlib_adapter-0.3.3-py3-none-any.whl

Total release size: 90.5 kB

Release files / cqlib_adapter-0.3.3.tar.gz

Download URL cqlib_adapter-0.3.3.tar.gz
Size 40.6 kB
Tags Source
SHA-256 checksum
How to use checksums
c8bac05ff0ce4cad521083af2b400cc5cdb1585217a1b55f83f91ba44671d690
BLAKE2b-256 checksum
How to use checksums
104c3871ea7ef88de093d99fcbefb34a2835af63b6014b9baf133a02794b6a0a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.20

Release files / cqlib_adapter-0.3.3-py3-none-any.whl

Download URL cqlib_adapter-0.3.3-py3-none-any.whl
Size 49.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b045bf845d8369127fa4a05a242bcc432446b415badac364fc3c4954eed882af
BLAKE2b-256 checksum
How to use checksums
30c7ee89b4dccb21100156c516c490fdc201e02e506ea6033c1aa96becae30a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.20

Security for cqlib-adapter 0.3.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