Skip to content

Introduction

Create an account in the Q-Alchemy Portal. The free service includes state preparation up to 12 qubits and simulator access with 4 MB RAM. Compare free, platform, and OEM access. For larger workloads, discuss business access with us.

This guide prepares a small, two-qubit Bell state. It needs no dataset download or quantum hardware: the service builds the preparation circuit, and you can check it locally.

Use Python 3.11–3.14 in a virtual environment. These commands install the SDK with the Qiskit integration used for local verification below.

Terminal window
python3 -m venv .venv
source .venv/bin/activate
python -m pip install "q-alchemy-sdk-py[qiskit]"

For the PennyLane example, also install python -m pip install "q-alchemy-sdk-py[pennylane]".

In the Portal, choose Settings → API Keys and create a key. Set it in the terminal where you will run Python:

Terminal window
export Q_ALCHEMY_API_KEY="your-api-key"

Replace your-api-key with your key. Keep it out of source control. The examples below read it from the environment.

Save this as first_state.py, then run python first_state.py in the same terminal. It submits a state-preparation job to Q-Alchemy and simulates the returned two-qubit circuit locally with Qiskit.

import os
import numpy as np
from qiskit import QuantumCircuit
from qiskit.quantum_info import Statevector, state_fidelity
from q_alchemy.initialize import q_alchemy_as_qasm
state = np.array([1, 0, 0, 1], dtype=complex) / np.sqrt(2)
qasm = q_alchemy_as_qasm(
state,
max_fidelity_loss=0.0,
api_key=os.environ["Q_ALCHEMY_API_KEY"],
)
prep = QuantumCircuit.from_qasm_str(qasm)
fidelity = state_fidelity(Statevector.from_instruction(prep), Statevector(state))
print(f"Qubits: {prep.num_qubits}")
print(f"Local simulation fidelity: {fidelity:.6f}")
assert prep.num_qubits == 2
assert fidelity > 0.99, "Check the returned preparation before continuing."

The input has equal amplitudes for 00 and 11. You should see Qubits: 2 and a local simulation fidelity close to 1.000000; the assertions check that the example produced a suitable result. Equivalent preparation circuits can have different gate sequences.

If Python reports KeyError: 'Q_ALCHEMY_API_KEY', set the key in the same terminal. For authentication errors, check your Portal key. For missing modules, activate the virtual environment and install the integration above.

Each example below is complete after installation and API-key setup. All use the same normalized input.

import os
import numpy as np
from q_alchemy.initialize import q_alchemy_as_qasm
state = np.array([1, 0, 0, 1], dtype=complex) / np.sqrt(2)
qasm, summary = q_alchemy_as_qasm(
state,
max_fidelity_loss=0.0,
api_key=os.environ["Q_ALCHEMY_API_KEY"],
return_summary=True,
)
print(qasm)
print(summary)

The PennyLane example asks Q-Alchemy to synthesize the preparation and executes that circuit on a local default.qubit simulator. It does not submit a hardware job.

  • Python SDK: integrations, batching, and the hosted sparse simulator.
  • Options: preparation methods, output formats, and method-specific controls.
  • Algorithm: how state preparation works and how to interpret its results.
  • Feasibility Suite: assess a wider workload with your resource and quality targets.

For a guided introduction, request a demo. Advanced integrations can use the REST API reference, built on PineXQ.