Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

time evolution + detuning dev #20

Merged
merged 33 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
7c2cb06
drafting stuff up
babcockt18 May 18, 2024
9d618f8
feat(qrc): Implement Magnus expansion for simulating quantum dynamics…
babcockt18 May 19, 2024
86f20b5
Add files via upload
Hirmay May 24, 2024
942c3d6
Merge pull request #15 from qBraid/Hirmay-patch-1
Hirmay May 24, 2024
60ed852
Base version of the OneHotEncode Function
May 31, 2024
b96fb94
Base version of the functions to load mnist data, perform local detun…
sbopanna May 31, 2024
2b716f3
Update pca.py
Hirmay Jun 5, 2024
27fbf28
Update encoding.py
Hirmay Jun 5, 2024
09bd7b2
Merge branch 'main' into krylov
ryanhill1 Jun 5, 2024
ae7e711
Merge branch 'notebook-experimentation' into develop
ryanhill1 Jun 5, 2024
0fb0329
Merge branch 'qbraid-algo-sooraj' into develop
ryanhill1 Jun 5, 2024
c6dad6f
unify dev progress
ryanhill1 Jun 10, 2024
34d72b6
ci/cd + packaging updates
ryanhill1 Jun 11, 2024
7e23172
fix workflows
ryanhill1 Jun 11, 2024
665a941
lazy load torchvision
ryanhill1 Jun 11, 2024
b18138f
fix headers skip
ryanhill1 Jun 11, 2024
5f3ea71
add code coverage badge
ryanhill1 Jun 11, 2024
ac8f2fe
feat(qrc): Implement Magnus expansion for simulating quantum dynamics…
babcockt18 May 19, 2024
a94ec4f
Refactor towards bloqade's built in evolution
babcockt18 Jun 27, 2024
b07c1c8
feat: update dependencies and add time evolution tests
babcockt18 Jun 29, 2024
bd6da5f
adding conditional logic for emulation vs hardware backend
babcockt18 Jun 30, 2024
61797f3
Merge branch 'bloqade-centric-refactor' of https://github.com/qBraid/…
babcockt18 Jul 3, 2024
d8a00ce
figuring out how to integrate dynamics and time_evolution
babcockt18 Jul 6, 2024
bee21d6
updating refs to uniform, scale, location functions-not classes
babcockt18 Jul 6, 2024
661aec1
updating dynamics, still wip migrating functionality properly
babcockt18 Jul 6, 2024
97fc0e0
Merge branch 'bloqade-centric-refactor' into rh1-dynamics
ryanhill1 Jul 10, 2024
d615204
updating dynamics.py
babcockt18 Jul 10, 2024
b04d9c9
check-in time evolution progress
ryanhill1 Jul 10, 2024
0ddadeb
Merge branch 'revising-dynamics-for-t-e' into rh1-dynamics
ryanhill1 Jul 10, 2024
34292b8
detuning layer dev
ryanhill1 Jul 10, 2024
aa50917
update docs + hide sklearn
ryanhill1 Jul 11, 2024
34774ed
fix pyproject
ryanhill1 Jul 11, 2024
09c95af
fix docs
ryanhill1 Jul 11, 2024
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<a href="https://github.com/qBraid/qbraid-algorithms/actions/workflows/main.yml">
<img src="https://github.com/qBraid/qbraid-algorithms/actions/workflows/main.yml/badge.svg?branch=main" alt="CI"/>
</a>
<a href="https://codecov.io/gh/qBraid/qbraid-algorithms">
<img src="https://codecov.io/gh/qBraid/qbraid-algorithms/graph/badge.svg?token=7jYcnneDys"/>
</a>
<a href="https://pypi.org/project/qbraid-algorithms/">
<img src="https://img.shields.io/pypi/v/qbraid-algorithms.svg?color=blue" alt="PyPI version"/>
</a>
Expand Down
Binary file removed docs/_static/cards/jupyter.png
Binary file not shown.
Binary file removed docs/_static/cards/python.png
Binary file not shown.
Binary file removed docs/_static/cards/terminal.png
Binary file not shown.
3 changes: 2 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import qbraid_algorithms

project = "qbraid-algorithms"
project = "qBraid"
copyright = "2024, qBraid Development Team"
author = "qBraid Development Team"

Expand All @@ -25,6 +25,7 @@
"sphinx.ext.autodoc",
"sphinx_autodoc_typehints",
"sphinx.ext.autosummary",
"sphinx_copybutton"
]

autodoc_mock_imports = ["torchvision"]
Expand Down
77 changes: 42 additions & 35 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
Documentation
==============

.. raw:: html

<html>
Expand Down Expand Up @@ -49,47 +46,57 @@ Documentation
</head>
<body>
<h1 style="text-align: center">
<img src="_static/logo.png" alt="qbraid logo" style="width:50px;height:50px;">
<img src="_static/logo.png" alt="qbraid logo" style="width:60px;height:60px;">
<span> qBraid</span>
<span style="color:#808080"></span>
<span style="color:#808080"> | algorithms</span>
</h1>
<p style="text-align:center;font-style:italic;color:#808080">
A cloud-based platform for quantum computing.
Build hybrid quantum-classical algorithms with qBraid.
</p>
<div class="row">
<div class="column">
<a href="https://docs.qbraid.com/projects/lab/en/latest/lab/overview.html">
<div class="card">
<h3>Lab</h3>
<img src="_static/cards/jupyter.png" alt="terminal" style="width:60px;height:60px;">
</div>
</a>
</div>

<div class="column">
<a href="https://docs.qbraid.com/projects/cli/en/latest/guide/overview.html">
<div class="card">
<h3>CLI</h3>
<img src="_static/cards/terminal.png" alt="terminal" style="width:60px;height:60px;">
</div>
</a>
</div>

<div class="column">
<a href="https://docs.qbraid.com/en/latest/sdk/overview.html">
<div class="card">
<h3>SDK</h3>
<img src="_static/cards/python.png" alt="terminal" style="width:60px;height:60px;">
</div>
</a>
</div>
</div>

</body>
</html>

|

:Release: |release|

Overview
---------

Python package for building, simulating, and benchmarking hybrid quantum-classical algorithms.


Installation
-------------

qbraid-algorithms requires Python 3.9 or greater, and can be installed with pip as follows:

.. code-block:: bash

pip install qbraid-algorithms


Install from Source
^^^^^^^^^^^^^^^^^^^^

You can also install from source by cloning this repository and running a pip install command in the root directory of the repository:

.. code-block:: bash

git clone https://github.com/qBraid/qbraid-algorithms.git
cd qbraid-algorithms
pip3 install .


Resources
----------

- `User Guide <https://docs.qbraid.com/algorithms/user-guide>`_
- `Example Notebooks <https://github.com/qBraid/qbraid-algorithms/tree/main/examples>`_
- `API Reference <https://sdk.qbraid.com/projects/algorithms/en/stable/api/qbraid_algorithms.html>`_

|

.. toctree::
:maxdepth: 1
:caption: API Reference
Expand Down
3 changes: 3 additions & 0 deletions examples/sandbox/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# qBraid-Algorithms Developer Sandbox

This sandbox directory is provided as a collaborative and temporary space where contributors can freely share experimental notebooks and early-stage code. Its main purpose is to increase transparency about ongoing work, thus enhancing collaboration. Feel free to push your notebooks and code frequently, regardless of their completeness or correctness. This directory will be removed with the release of version 0.1 of the `qbraid-algorithms` project.
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dependencies = ["torch>=2.3.0,<3.0", "numpy>=1.17,<2.1", "scipy~=1.13.1", "bloqa

[project.urls]
Homepage = "https://github.com/qBraid/qbraid-algorithms"
Documentation = "https://docs.qbraid.com/en/stable/"
Documentation = "https://docs.qbraid.com"
"Bug Tracker" = "https://github.com/qBraid/qbraid-algorithms/issues"
Discord = "https://discord.gg/TPBU2sa8Et"
"Launch on Lab" = "https://account.qbraid.com/?gitHubUrl=https://github.com/qBraid/qbraid-algorithms.git"
Expand All @@ -38,7 +38,7 @@ Discord = "https://discord.gg/TPBU2sa8Et"
visualization = ["matplotlib"]
test = ["pytest", "pytest-cov"]
lint = ["isort", "ruff", "qbraid-cli"]
docs = ["sphinx~=7.3.7", "sphinx-autodoc-typehints>=1.24,<2.3", "sphinx-rtd-theme~=2.0.0", "docutils<0.22"]
docs = ["sphinx~=7.3.7", "sphinx-autodoc-typehints>=1.24,<2.3", "sphinx-rtd-theme~=2.0.0", "docutils<0.22", "sphinx-copybutton"]

[tool.setuptools_scm]
write_to = "qbraid_algorithms/_version.py"
Expand Down Expand Up @@ -67,7 +67,7 @@ exclude = '''

[tool.pylint.'MESSAGES CONTROL']
max-line-length = 100
disable = "W0108, W0511, W0401, R0902"
disable = "W0108,W0511,W0401,R0902,R0903,R0913"

[tool.pylint.MASTER]
ignore-paths = [
Expand Down
27 changes: 24 additions & 3 deletions qbraid_algorithms/qrc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,31 @@

QRCModel
MagnusExpansion
DetuningLayer
MagnusExpansion
AnalogProgramEvolver

Functions
----------

.. autosummary::
:toctree: ../stubs/

one_hot_encoding
pca_reduction

"""

from .magnus import MagnusExpansion
from .model import QRCModel
from .encoding import one_hot_encoding, pca_reduction
from .magnus_expansion import MagnusExpansion
from .qrc_model import DetuningLayer, QRCModel
from .time_evolution import AnalogProgramEvolver

__all__ = ["QRCModel", "MagnusExpansion"]
__all__ = [
"QRCModel",
"MagnusExpansion",
"DetuningLayer",
"AnalogProgramEvolver",
"one_hot_encoding",
"pca_reduction",
]
127 changes: 0 additions & 127 deletions qbraid_algorithms/qrc/dynamics.py

This file was deleted.

45 changes: 43 additions & 2 deletions qbraid_algorithms/qrc/encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
# THERE IS NO WARRANTY for the qBraid-SDK, as per Section 15 of the GPL v3.

"""
Module for encoding of data.
Module for encoding of classical data.

"""
import numpy as np
import torch
from sklearn.preprocessing import OneHotEncoder


def one_hot_encoding(labels: np.ndarray, train: bool = True) -> torch.Tensor:
Expand All @@ -28,10 +27,52 @@
torch.Tensor: The one-hot encoded matrix where each row corresponds to a label.

"""
# pylint: disable-next=import-outside-toplevel
from sklearn.preprocessing import OneHotEncoder

Check warning on line 31 in qbraid_algorithms/qrc/encoding.py

View check run for this annotation

Codecov / codecov/patch

qbraid_algorithms/qrc/encoding.py#L31

Added line #L31 was not covered by tests

encoder = OneHotEncoder(sparse_output=False)
reshaped_data = labels.reshape(-1, 1)
if train:
encoded_data = encoder.fit_transform(reshaped_data)
else:
encoded_data = encoder.transform(reshaped_data)
return encoded_data


def pca_reduction(
data: torch.Tensor,
n_components: int,
data_dim: int,
delta_max: int,
train: bool = True,
) -> torch.Tensor:
"""
Perform PCA reduction on the provided data using PyTorch's pca_lowrank to
reduce its dimensionality.

Args:
data (torch.Tensor): The input data tensor where each row represents a sample.
n_components (int): The number of principal components to retain.
data_dim (int): The dimension of the input data required for doing PCA.
delta_max (int): Scaling factor to bring PCA vals into a feasible range for local detuning.
train (bool, optional): Whether the data is training data. Defaults to True.

Returns:
torch.Tensor: The transformed data
"""
# pylint: disable-next=import-outside-toplevel
from sklearn.decomposition import PCA

Check warning on line 64 in qbraid_algorithms/qrc/encoding.py

View check run for this annotation

Codecov / codecov/patch

qbraid_algorithms/qrc/encoding.py#L64

Added line #L64 was not covered by tests

# Perform PCA on training data
pca = PCA(n_components=n_components)
data_array: np.ndarray = data.data.numpy()
data_reshaped = data_array.reshape(-1, data_dim)
if train:
data_pca = pca.fit_transform(data_reshaped)

Check warning on line 71 in qbraid_algorithms/qrc/encoding.py

View check run for this annotation

Codecov / codecov/patch

qbraid_algorithms/qrc/encoding.py#L67-L71

Added lines #L67 - L71 were not covered by tests
else:
data_pca = pca.transform(data_reshaped)

Check warning on line 73 in qbraid_algorithms/qrc/encoding.py

View check run for this annotation

Codecov / codecov/patch

qbraid_algorithms/qrc/encoding.py#L73

Added line #L73 was not covered by tests

# Scale PCA values to feasible range of local detuning
scaled_data_pca = data_pca / np.max(np.abs(data_pca)) * delta_max

Check warning on line 76 in qbraid_algorithms/qrc/encoding.py

View check run for this annotation

Codecov / codecov/patch

qbraid_algorithms/qrc/encoding.py#L76

Added line #L76 was not covered by tests

return scaled_data_pca

Check warning on line 78 in qbraid_algorithms/qrc/encoding.py

View check run for this annotation

Codecov / codecov/patch

qbraid_algorithms/qrc/encoding.py#L78

Added line #L78 was not covered by tests
Loading