Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: CI

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:

lint:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'

steps:
# Check out code
- name: Checkout code
uses: actions/checkout@v6

# Install Python via UV
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
python-version: "3.13"
enable-cache: true

# Setup Topologiq
- name: Install dependencies
run: uv sync --group dev

# Ruff using local deps
- name: Ruff
run: uv run ruff check .
61 changes: 53 additions & 8 deletions src/topologiq/assets/pyzx_graphs.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
"""PyZX graphs to use in examples, demonstrations and testing.

Usage:
Call any graph from a separate script.

"""

import matplotlib
import matplotlib.figure
import pyzx as zx
from pyzx.graph.base import BaseGraph
from pyzx.graph.graph_s import GraphS
from typing import Optional, Tuple, Union
import matplotlib.figure

def cnot(draw_graph: bool = False) -> Tuple[Union[BaseGraph, GraphS], Optional[matplotlib.figure.Figure]]:

def cnot(draw_graph: bool = False) -> tuple[BaseGraph | GraphS, matplotlib.figure.Figure | None]:
"""Produce a PyZX graph corresponding to a CNOT.

Args:
draw_graph: Whether to pop-up PyZX graph visualisation or not.

Returns:
g: The PyZX graph corresponding to the requested circuit.

"""

c = zx.Circuit(2)
c.add_gate("CNOT", 1, 0)
Expand All @@ -18,7 +34,16 @@ def cnot(draw_graph: bool = False) -> Tuple[Union[BaseGraph, GraphS], Optional[m
return g, fig


def cnots(draw_graph: bool = False) -> Tuple[Union[BaseGraph, GraphS], Optional[matplotlib.figure.Figure]]:
def cnots(draw_graph: bool = False) -> tuple[BaseGraph | GraphS, matplotlib.figure.Figure | None]:
"""Produce a PyZX graph corresponding to three CNOTs.

Args:
draw_graph: Whether to pop-up PyZX graph visualisation or not.

Returns:
g: The PyZX graph corresponding to the requested circuit.

"""

c = zx.Circuit(2)
c.add_gate("CNOT", 0, 1)
Expand All @@ -34,7 +59,16 @@ def cnots(draw_graph: bool = False) -> Tuple[Union[BaseGraph, GraphS], Optional[
return g, fig


def simple_mess(draw_graph: bool = False) -> Tuple[Union[BaseGraph, GraphS], Optional[matplotlib.figure.Figure]]:
def simple_mess(draw_graph: bool = False) -> tuple[BaseGraph | GraphS, matplotlib.figure.Figure | None]:
"""Produce a PyZX graph corresponding to a small CNOT-based circuit.

Args:
draw_graph: Whether to pop-up PyZX graph visualisation or not.

Returns:
g: The PyZX graph corresponding to the requested circuit.

"""

c = zx.Circuit(3)
c.add_gate("CNOT", 1, 2)
Expand All @@ -45,7 +79,7 @@ def simple_mess(draw_graph: bool = False) -> Tuple[Union[BaseGraph, GraphS], Opt
c.add_gate("CNOT", 0, 2)

g = c.to_graph()

fig = None
if draw_graph:
fig = zx.draw(g, labels=True)
Expand All @@ -57,7 +91,18 @@ def random_graph(
qubit_n: int,
depth: int,
draw_graph: bool = False
) -> Tuple[Union[BaseGraph, GraphS] | None, matplotlib.figure.Figure] | None:
) -> tuple[BaseGraph | GraphS | None, matplotlib.figure.Figure | None]:
"""Produce a random PyZX graph.

Args:
qubit_n: The number of qubit lines in the desired graph.
depth: The depth of the desired graph.
draw_graph: Whether to pop-up PyZX graph visualisation or not.

Returns:
g: The PyZX graph corresponding to the requested circuit.

"""

# Generate inside loop to check graph integrity
# PyZX sometimes generates graphs of disconnected subgraphs,
Expand Down Expand Up @@ -94,7 +139,7 @@ def random_graph(
# Return if all IDs are present
if draw_graph:
fig = zx.draw(g)

# Return graph and figure
return g, fig

Expand Down
14 changes: 8 additions & 6 deletions src/topologiq/assets/qiskit_save_qpy.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
"""
Saves Qiskit circuits into Qiskit's .qpy native format.
"""Save Qiskit circuits into Qiskit's .qpy native format.

Usage:
Call `save_to_qpy` from a separate circuit with a path for the desired .qpy file and a qiskit circuit encoding.

"""

from pathlib import Path
from qiskit.circuit import QuantumCircuit

from qiskit import qpy
from qiskit.circuit import QuantumCircuit


def save_to_qpy(path_to_output: Path, qc: QuantumCircuit):
"""Save a Qiskit circuit to Qiskit's native .qpy format.

Args:
Args:
path_to_output: path to desired .qpy output file.
qc: Qiskit encoding for the desired circuit

Returns
n/a. Function saves to file.
Returns:
n/a. Function saves to file.

"""

with open(path_to_output, 'wb') as f:
Expand Down
14 changes: 13 additions & 1 deletion src/topologiq/assets/simple_graphs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
from topologiq.utils.classes import SimpleDictGraph
"""Simple dictionary-based graph circuits to use in examples, demonstrations and testing.

Usage:
Call any graph from a separate script.

"""

from topologiq.utils.classes import SimpleDictGraph

# Steane code with minimal spider count
steane: SimpleDictGraph = {
"nodes": [
(1, "X"),
Expand Down Expand Up @@ -38,6 +45,8 @@
],
}

# Slightly obfuscated Steane code
# +1 spider relative to minimal spider-count
steane_obfs: SimpleDictGraph = {
"nodes": [
(1, "Z"),
Expand Down Expand Up @@ -76,6 +85,7 @@
],
}

# Line of Hadamards
hadamard_line: SimpleDictGraph = {
"nodes": [
(0, "Z"),
Expand All @@ -94,6 +104,7 @@
],
}

# Y-shaped graph made of Hadamards
hadamard_bend: SimpleDictGraph = {
"nodes": [
(0, "Z"),
Expand All @@ -112,6 +123,7 @@
],
}

# Steane-like encoding with several Hadamards
hadamard_mess: SimpleDictGraph = {
"nodes": [
(1, "X"),
Expand Down