As quantum software development evolves, applying modern CI/CD (Continuous Integration and Continuous Deployment) practices ensures efficient collaboration, reliable code, and faster innovation. Qiskit (IBM) and Cirq (Google) are two leading quantum frameworks, both built in Python and widely used for simulating and running quantum circuits.
Setting up a CI/CD pipeline for these frameworks enables automatic testing, environment setup, code validation, and deployment to cloud environments or research platforms.
1. Why Use CI/CD in Quantum Projects?
Quantum computing projects benefit from CI/CD for several reasons:
- Rapid prototyping and validation of quantum circuits.
- Collaboration among teams with reliable version control.
- Error prevention through automated testing before merging.
- Consistency across different environments (local, test, production).
- Documentation validation for research reproducibility.
2. Basic Project Structure
Organize your Qiskit/Cirq project with a clean structure:
/quantum-project
├── main.py
├── circuits/
│ └── bell_circuit.py
├── tests/
│ └── test_circuits.py
├── requirements.txt
├── README.md
└── .github/
└── workflows/
└── ci.yml
3. Workflow with GitHub Actions (CI Pipeline)
A GitHub Actions pipeline file .github/workflows/ci.yml
automates the process.
name: Quantum CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install dependencies
run: |
pip install --upgrade pip
pip install -r requirements.txt
- name: Run unit tests
run: |
pytest tests/
4. Sample requirements.txt
For Qiskit projects:
qiskit==1.0.0
pytest
For Cirq projects:
cirq
pytest
Optionally include tools for code quality:
black
flake8
mypy
5. Writing Tests
Example test for Qiskit (tests/test_circuits.py
):
from qiskit import QuantumCircuit
def test_bell_state():
qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0, 1)
assert qc.depth() == 2
For Cirq:
import cirq
def test_cirq_circuit():
qubit = cirq.LineQubit(0)
circuit = cirq.Circuit(cirq.X(qubit))
assert len(circuit) == 1
6. Optional Additions to Pipeline
a. Linting and Formatting
- name: Lint with flake8
run: flake8 .
b. Type Checking with mypy
- name: Static Type Checking
run: mypy .
c. Notebook Testing (if using Jupyter)
- name: Test Jupyter Notebooks
run: |
pip install nbval
pytest --nbval notebooks/
7. Deployment Options
Quantum projects can also deploy:
- Simulation Results Dashboards (e.g., via Streamlit or Flask).
- Cloud Submissions to IBM Q Experience or Google Quantum Cloud using API tokens (stored in GitHub Secrets).
- Publishing Libraries to PyPI or GitHub Packages via release pipelines.
8. GitHub Secrets for API Access
If using cloud quantum backends, store your credentials securely:
IBMQ_API_TOKEN
for QiskitGOOGLE_CLOUD_KEY
or service account token for Cirq/GCP
Use secrets in workflow:
env:
IBMQ_API_TOKEN: ${{ secrets.IBMQ_API_TOKEN }}
9. Multi-Framework Testing
If your project supports both Qiskit and Cirq, you can define a matrix strategy in your pipeline:
strategy:
matrix:
sdk: [qiskit, cirq]
Then conditionally install dependencies and run appropriate tests based on the selected SDK.
10. Benefits of CI/CD in Quantum Software
- Scalability: Support large, modular quantum projects with confidence.
- Traceability: Track failures and bug fixes through automated logs.
- Team Agility: Encourage faster iteration in multi-developer environments.
- Community Readiness: Open-source contributions are easier to validate.