Skip to main content

No project description provided

Project description

MatchCake

Star on GitHub GitHub forks Python 3.6 downloads PyPI version License

Tests Workflow Dist Workflow Doc Workflow Code style: black codecov

Description

MatchCake is a Python package that provides a new PennyLane device for simulating a specific class of quantum circuits called Matchgate circuits or matchcircuits. These circuits are made with matchgates, a class of restricted quantum unitaries that are parity-preserving and operate on nearest-neighbor qubits. These constraints lead to matchgates being classically simulable in polynomial time.

Additionally, this package provides quantum kernels made with scikit-learn API allowing the use matchcircuits as kernels in quantum machine learning algorithms. One way to use these kernels could be in a Support Vector Machine (SVM). In the benchmark/classification folder, you can find some scripts that use SVM with matchcircuits as a kernel to classify the Iris dataset, the Breast Cancer dataset, and the Digits dataset in polynomial time with high accuracy.

Note that this package is built on PennyLane and PyTorch. This means that only the NumPy and PyTorch backends are compatible. Other backends provided by Autoray, such as JAX and TensorFlow, are not supported. We highly recommend using PyTorch as the backend when working with MatchCake.

Installation

Method Commands
poetry poetry add matchcake
uv uv add matchcake
PyPi pip install MatchCake
source pip install git+https://github.com/MatchCake/MatchCake

Last unstable version

To install the latest unstable version, download the latest version from https://github.com/MatchCake/MatchCake@dev.

CUDA installation

To use MatchCake with cuda, you can add --extra cu128 to the installation commands above. This will install pytorch with CUDA 12.8.

Quick Usage Preview

Quantum Circuit Simulation with MatchCake

import matchcake as mc
import pennylane as qml
import numpy as np
from pennylane.ops.qubit.observables import BasisStateProjector

# Create a Non-Interacting Fermionic Device
nif_device = mc.NonInteractingFermionicDevice(wires=4)
initial_state = np.zeros(len(nif_device.wires), dtype=int)

# Define a quantum circuit
def circuit(params, wires, initial_state=None):
    qml.BasisState(initial_state, wires=wires)
    for i, even_wire in enumerate(wires[:-1:2]):
        idx = list(wires).index(even_wire)
        curr_wires = [wires[idx], wires[idx + 1]]
        mc.operations.fRXX(params, wires=curr_wires)
        mc.operations.fRYY(params, wires=curr_wires)
        mc.operations.fRZZ(params, wires=curr_wires)
    for i, odd_wire in enumerate(wires[1:-1:2]):
        idx = list(wires).index(odd_wire)
        mc.operations.fSWAP(wires=[wires[idx], wires[idx + 1]])
    projector: BasisStateProjector = qml.Projector(initial_state, wires=wires)
    return qml.expval(projector)

# Create a QNode
nif_qnode = qml.QNode(circuit, nif_device)
qml.draw_mpl(nif_qnode)(np.array([0.1, 0.2]), wires=nif_device.wires, initial_state=initial_state)

# Evaluate the QNode
expval = nif_qnode(np.random.random(2), wires=nif_device.wires, initial_state=initial_state)
print(f"Expectation value: {expval}")

Data Classification with MatchCake

from matchcake.ml.kernels import FermionicPQCKernel
from matchcake.ml.svm import FixedSizeSVC
from matchcake.ml.visualisation import ClassificationVisualizer
from sklearn import datasets
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import MinMaxScaler

# Load the iris dataset
X, y = datasets.load_iris(return_X_y=True)
X = MinMaxScaler(feature_range=(0, 1)).fit_transform(X)
x_train, x_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)

# Create and fit the model
model = FixedSizeSVC(kernel_cls=FermionicPQCKernel, kernel_kwargs=dict(size=4), random_state=0)
model.fit(x_train, y_train)

# Evaluate the model
test_accuracy = model.score(x_test, y_test)
print(f"Test accuracy: {test_accuracy * 100:.2f}%")

# Visualize the classification
viz = ClassificationVisualizer(x=X, n_pts=1_000)
viz.plot_2d_decision_boundaries(model=model, y=y, show=True)

Tutorials

Notes

  • This package is still in development and some features may not be available yet.
  • The documentation is still in development and may not be complete yet.

About

This work was supported by the Ministère de l'Économie, de l'Innovation et de l'Énergie du Québec through its Research Chair in Quantum Computing, an NSERC Discovery grant, and the Canada First Research Excellence Fund.

Important Links

Found a bug or have a feature request?

License

Apache License 2.0

Citation

IEEE Xplore paper:

@INPROCEEDINGS{10821385,
  author={Gince, Jérémie and Pagé, Jean-Michel and Armenta, Marco and Sarkar, Ayana and Kourtis, Stefanos},
  booktitle={2024 IEEE International Conference on Quantum Computing and Engineering (QCE)}, 
  title={Fermionic Machine Learning}, 
  year={2024},
  volume={01},
  number={},
  pages={1672-1678},
  keywords={Runtime;Quantum entanglement;Computational modeling;Benchmark testing;Rendering (computer graphics);Hardware;Kernel;Integrated circuit modeling;Quantum circuit;Standards;Quantum machine learning;quantum kernel methods;matchgate circuits;fermionic quantum computation;data classification},
  doi={10.1109/QCE60285.2024.00195}
}

ArXiv paper:

@misc{gince2024fermionic,
      title={Fermionic Machine Learning}, 
      author={Jérémie Gince and Jean-Michel Pagé and Marco Armenta and Ayana Sarkar and Stefanos Kourtis},
      year={2024},
      eprint={2404.19032},
      archivePrefix={arXiv},
      primaryClass={quant-ph}
}

Repository:

@misc{matchcake_Gince2023,
  title={Fermionic Machine learning},
  author={Jérémie Gince},
  year={2023},
  publisher={Université de Sherbrooke},
  url={https://github.com/MatchCake/MatchCake},
}

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

matchcake-0.0.6.tar.gz (116.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

matchcake-0.0.6-py3-none-any.whl (154.2 kB view details)

Uploaded Python 3

File details

Details for the file matchcake-0.0.6.tar.gz.

File metadata

  • Download URL: matchcake-0.0.6.tar.gz
  • Upload date:
  • Size: 116.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for matchcake-0.0.6.tar.gz
Algorithm Hash digest
SHA256 a5ffe2ed90add84905c91bed0d5846fb115900d4eb060745298203046ca14de5
MD5 af54fd6e7e89be68b463c43712e16f8d
BLAKE2b-256 4c6fc66318a099ac4bca60a958e7956997dae6901e36cf04484b60068b12dd1b

See more details on using hashes here.

Provenance

The following attestation bundles were made for matchcake-0.0.6.tar.gz:

Publisher: build_dist.yml on MatchCake/MatchCake

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file matchcake-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: matchcake-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 154.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for matchcake-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 6a8eb38754caeaa66876b226f9b547e61f868785cd939465270fe6aedde1b0d2
MD5 acba15efe776db99f113b24010900380
BLAKE2b-256 0d684ac08cbdbe5e0c97fb7681fc93d97c15915fec9e5258e20e44e855130b24

See more details on using hashes here.

Provenance

The following attestation bundles were made for matchcake-0.0.6-py3-none-any.whl:

Publisher: build_dist.yml on MatchCake/MatchCake

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page