Skip to main content

A Quantum Circuit DSL

Project description

abraxas

A tiny DSL to compile to quantum circuits. The goal is to speed up the time it takes to write small stupid circuits. Anything beyond a certain complexity should be written in the respective languages directlt directly.

QiskitCudaQPennylane

Install

pip install abrax

Syntax

  • Start with a - to denote a wire (you can also count -0, -1, -2 as wires, these are just comments)
  • All gates are case insensitive with NO SPACES BETWEEN GATE AND ARGUMENTS
  • Arguments are in parenthesis () and separated by commas , ex: H CX(2) CRX(3.1415,3)
  • Abraxas is only the circuit part parser. All the other gymnastics of creating circuits/allocating memory/running them is still up to you.

Examples

toQiskit

from qiskit import QuantumCircuit
from abrax import toQiskit

qc = QuantumCircuit(3)
qc = toQiskit(qc, f"""
  - H CX(2) RX({3.1415})
  - H -     CX(2)
  - H X     RY(55)
  """
)

# IS THE SAME AS
#         ┌───┐┌───┐┌────────────┐
#    q_0: ┤ H ├┤ X ├┤ Rx(3.1415) ├────────────────
#         ├───┤└─┬─┘└────────────┘┌───┐
#    q_1: ┤ H ├──┼────────────────┤ X ├───────────
#         ├───┤  │      ┌───┐     └─┬─┘┌────────┐
#    q_2: ┤ H ├──■──────┤ X ├───────■──┤ Ry(55) ├─
#         └───┘         └───┘          └────────┘

toPennylane

import pennylane as qml
from abrax import toPennyLane

CIRC = f"""
- H CX(2) RX(θ1)
- H -     CX(2)
- H X     RY(θ2)
"""

maker, params = toPennylane(CIRC)
def circ():
  # 0.0, 0.1 since 2 params
  params = [0.1 * i for i in range(len(params))]
  maker(qml, params)

  return qml.probs()

circuit = qml.QNode(circ, qml.device('default.qubit', wires=3))
# IS THE SAME AS
# 0: ──H─╭X──RX(0.00)───────────────┤  Probs
# 1: ──H─│────────────╭X────────────┤  Probs
# 2: ──H─╰●──X────────╰●──RY(0.01)──┤  Probs

toCudaq

from cudaq import make_kernel, sample
from abrax import toCudaq

CIRC = f"""
-0 H CX(2) RX(θ1)
-1 H -     CX(2)
-2 H X     RY(θ2)
"""

kernel, thetas = make_kernel(list)
qubits = kernel.qalloc(3)

cudaO = {
  'kernel': kernel,
  'qubits': qubits,
  'quake': thetas,
  # this gets overwritten by the parser
  'params': 0,
}
kernel = toCudaq(cudaO, CIRC)
# expect 0.0, 0.1 since 2 params
vals = [0.1 * i for i in range(cudaO['params'])]
result = sample(kernel, vals)
print(result)

toPrime

The prime string acts as a translation intermediate between various libraries. You can come to prime from Qiskit and go anywhere. (Coming to Prime from Pennylane/CudaQ is not supported yet)

from qiskit.circuit.library import EfficientSU2
from abrax import toPrime

qc = EfficientSU2(3, reps=1).decompose()
string = toPrime(qc)

# IS THE SAME AS
# -0 ry(θ[0]) rz(θ[3]) cx(1)    ry(θ[6])
# -1 ry(θ[1]) rz(θ[4]) cx(2)    ry(θ[7])
# -2 ry(θ[2]) rz(θ[5]) ry(θ[8]) rz(θ[11])

You can now even take this string and pass into toPennylane or toCudaq to convert to run it in them. Ex.

# string from above
maker, params = toPennylane(string)
def circ():
  # 12 params so 0.0, 0.1...1.1
  params = [0.1 * i for i in range(len(params))]
  maker(qml, params)

  return qml.probs()

circuit = qml.QNode(circ, qml.device('default.qubit', wires=3))

Append

Abraxas can also add to an existing circuit since it takes in your circuit and simply appends to it. So you can pass in existing QuantumCircuit/CUDA Kernel, or add more operations in the Pennylane circ wrapper.

Supported conversions:

graph TD
  A[Qiskit] -->|"toPrime()"| B[String]
  B -->|"toQiskit()"| C[Qiskit]
  B -->|"toPennylane()"| D[Pennylane]
  B -->|"toCudaq()"| E[CudaQuantum]

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

abrax-0.4.1.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

abrax-0.4.1-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file abrax-0.4.1.tar.gz.

File metadata

  • Download URL: abrax-0.4.1.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.7

File hashes

Hashes for abrax-0.4.1.tar.gz
Algorithm Hash digest
SHA256 546f728291c7767e65a0e78e18fae1c67d388e5e180e72a32697514202e3b38a
MD5 0597f8b7a344eae88cc54fb87b555928
BLAKE2b-256 6c11e2fa71f4dcd785b33fe5f6a43fb93e94c4a16bf6980476128b2d31961cdb

See more details on using hashes here.

File details

Details for the file abrax-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: abrax-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.7

File hashes

Hashes for abrax-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b65918927681d2644347a1d8b6f642a9bf8c589757af60085d181ce3104fb095
MD5 8ad40446f697942e4937be330f2d7b0b
BLAKE2b-256 7d7ccef02277f656a09b23514ee1f65ef28b1570c319f32b6face173e940b47b

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