Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
db4024c
[feat] skeleton for AnalysisCache
yhteoh Feb 22, 2025
d322480
[format] include copyright notice
yhteoh Feb 22, 2025
e95fe9c
[dependency] added dev dependency for ruff and pre-commit (for format…
yhteoh Feb 22, 2025
f3aea24
[feature] implemented integrated analysis with AnalysisCache, Analysi…
yhteoh Feb 22, 2025
0a2305e
[format] Added ruff lint config to pyproject.toml
yhteoh Feb 22, 2025
5369fcc
[format] Ran ruff linting and formatting
yhteoh Feb 22, 2025
3e890e1
[test] Added test for new analysis infrastructure
yhteoh Feb 22, 2025
242ae97
[clean] Removed commented out old code
yhteoh Feb 22, 2025
9a909aa
[feat] Added feature for automated scheduling for analysis with Analy…
yhteoh Feb 22, 2025
a074a8d
[test] Added test for automated analysis
yhteoh Feb 22, 2025
ee30854
[fix] Run analysis when there is no valid entry in the AnalysisCache
yhteoh Feb 22, 2025
336598e
[test] Rewrite and conversion rules with automated analysis
yhteoh Feb 22, 2025
e2e12c4
[test] Added test for rules
yhteoh Feb 22, 2025
d9c4c18
[test] Refactor test
yhteoh Feb 22, 2025
69245a9
[refactor] Use Chain to generate an analysis pass depending on the An…
yhteoh Feb 22, 2025
faab087
[test] fix missing super().__init__() in PrintWalkOrder rule
yhteoh Feb 22, 2025
aae2adb
[feat] Added verbose flag for PassBase and removed saving of the last…
yhteoh Feb 22, 2025
7d01ca3
[refactor] Handling of verbose in PassBase with set_verbose method al…
yhteoh Feb 23, 2025
ab33d22
[test] Added tests for rewriters
yhteoh Feb 23, 2025
c6ae9ef
[format] Include copyright notice
yhteoh Feb 23, 2025
0c95256
[test,action] Update pytest github action
yhteoh Feb 23, 2025
e8fbed4
[dependency] Added dev dependency on jupyter
yhteoh Feb 27, 2025
c83acb1
[format] run formatter on all code
yhteoh Feb 27, 2025
47061dd
Merge branch 'main' of https://github.com/OpenQuantumDesign/oqd-compi…
yhteoh Sep 4, 2025
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
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
- Subsystem:


* **Other information** (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, gitter, etc)
* **Other information** (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, gitter, etc)
4 changes: 2 additions & 2 deletions .github/workflows/check_copyright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ jobs:
- name: Check license & copyright headers
uses: viperproject/check-license-header@v2
with:
path:
path:
config: .github/workflows/check_copyright_config.json
# strict: true
# strict: true
2 changes: 1 addition & 1 deletion .github/workflows/check_mkdocs_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ jobs:
uses: astral-sh/setup-uv@v4
# - run: cp -r examples/ docs/examples/
- run: uv pip install .[docs] --system
- run: mkdocs build
- run: mkdocs build
2 changes: 1 addition & 1 deletion .github/workflows/copyright.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# limitations under the License.
37 changes: 18 additions & 19 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,34 @@ permissions:
contents: read

jobs:
build:
runs-on: ${{ matrix.os }}
test:
strategy:
fail-fast: false
matrix:
version:
python-version:
- "3.10"
- "3.11"
- "3.12"
- "3.13"
os: ["ubuntu-latest", "windows-latest", "macos-latest"]
os:
- ubuntu-latest
- macos-latest
- windows-latest
arch:
- x64
name: Test ${{ matrix.version }} on ${{ matrix.os }} (${{ matrix.arch }})

runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
- name: Checkout repo
uses: actions/checkout@v4
- name: Install uv and set the python version
uses: astral-sh/setup-uv@v5
with:
python-version: ${{ matrix.version }}

- name: Install uv
uses: astral-sh/setup-uv@v4
# with:
# enable-cache: true

- name: Install the project
run: uv pip install .[tests] --system

enable-cache: true
python-version: ${{ matrix.python-version }}
- name: Install repo
run: |
uv sync --extra tests
- name: Run tests
run: uv run pytest tests
run: |
uv run pytest tests -vv
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
[![License: Apache 2.0](https://img.shields.io/badge/license-Apache%202.0-brightgreen.svg)](https://opensource.org/licenses/Apache-2.0)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)



### What's here:
This repository contains the supporting infrastructure, base classes, and abstractions

This repository contains the supporting infrastructure, base classes, and abstractions
for creating custom compiler analysis, verification, and transformation passes.
The modules in the repository are utilized for, e.g., lowering from the analog to atomic
intermediate representations, and the atomic representation to bare metal descriptions of
Expand All @@ -23,11 +22,13 @@ quantum programs.
## Installation

Install with `pip`:

```bash
pip install oqd-compiler-infrastructure
```

or alternatively from `git`:

```bash
pip install git+https://github.com/OpenQuantumDesign/oqd-compiler-infrastructure.git
```
Expand All @@ -37,6 +38,7 @@ pip install git+https://github.com/OpenQuantumDesign/oqd-compiler-infrastructure
You can use this package with Nix in several ways:

1. Using the development environment:

```bash
# Clone the repository
git clone https://github.com/OpenQuantumDesign/oqd-compiler-infrastructure.git
Expand All @@ -47,6 +49,7 @@ nix develop
```

2. Building the package:

```bash
nix build github:OpenQuantumDesign/oqd-compiler-infrastructure
```
Expand Down Expand Up @@ -187,6 +190,7 @@ block-beta
class IR normal
class RealTime normal
```

The lowering and compilation passes, used in the vertical lines connecting
abstraction layers, are based on the compiler infrastructure components contained
in this repository.
abstraction layers, are based on the compiler infrastructure components contained
in this repository.
10 changes: 6 additions & 4 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#
#

<p align="center">
<img src="img/oqd-logo-black.png#only-light" alt="Logo" style="max-height: 200px;">
Expand All @@ -18,7 +18,8 @@
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)

### What's here:
This repository contains the supporting infrastructure, base classes, and abstractions

This repository contains the supporting infrastructure, base classes, and abstractions
for creating custom compiler analysis, verification, and transformation passes.
The modules in the repository are utilized for, e.g., lowering from the analog to atomic
intermediate representations, and the atomic representation to base metal descriptions of
Expand Down Expand Up @@ -115,6 +116,7 @@ block-beta
class IR normal
class RealTime normal
```

The lowering and compilation passes, used in the vertical lines connecting
abstraction layers, are based on the compiler infrastructure components contained
in this repository.
abstraction layers, are based on the compiler infrastructure components contained
in this repository.
2 changes: 1 addition & 1 deletion docs/stylesheets/admonition_template.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
background-color: #FFFFFF;
-webkit-mask-image: var(--md-admonition-icon--template);
mask-image: var(--md-admonition-icon--template);
}
}
3 changes: 0 additions & 3 deletions docs/stylesheets/extra_admonitions.css
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,3 @@
-webkit-mask-image: var(--md-admonition-icon--acknowledgement);
mask-image: var(--md-admonition-icon--acknowledgement);
}



1 change: 0 additions & 1 deletion docs/tutorial/calculator.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"outputs": [],
"source": [
"class MyExpr(TypeReflectBaseModel):\n",
"\n",
" def __add__(self, other):\n",
" return MyAdd(left=self, right=other)\n",
"\n",
Expand Down
24 changes: 15 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ name = "oqd-compiler-infrastructure"
version = "0.1.0"
requires-python = ">=3.10"
readme = "README.md"
license = {text = "Apache 2.0"}
license = { text = "Apache 2.0" }
keywords = ["quantum", "computing", "compiler", "transpilation"]
classifiers = [
"Development Status :: 3 - Alpha",
Expand All @@ -27,26 +27,32 @@ classifiers = [
]


dependencies = [
"pydantic>=2, <3",
]
dependencies = ["pydantic>=2, <3"]

[project.optional-dependencies]
docs = [
"pymdown-extensions",
"mkdocstrings",
"mkdocs-material",
"mkdocstrings-python",
"mdx_truly_sane_lists",
"pymdown-extensions",
"mkdocstrings",
"mkdocs-material",
"mkdocstrings-python",
"mdx_truly_sane_lists",
]
tests = ["pytest"]

[tool.setuptools.packages.find]
where = ["src"]
include = ["oqd_compiler_infrastructure*"]

[dependency-groups]
dev = ["jupyter>=1.1.1", "pre-commit>=4.1.0", "ruff>=0.9.7"]


[project.urls]
Homepage = "https://github.com/OpenQuantumDesign/oqd-compiler-infrastructure"
Repository = "https://github.com/OpenQuantumDesign/oqd-compiler-infrastructure.git"
Issues = "https://github.com/OpenQuantumDesign/oqd-compiler-infrastructure/issues"


[tool.ruff.lint]
select = ["E4", "E7", "E9", "F", "I"]
fixable = ["ALL"]
7 changes: 6 additions & 1 deletion src/oqd_compiler_infrastructure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .analysis import AnalysisCache, AnalysisRequirements, AnalysisResult
from .base import PassBase
from .interface import TypeReflectBaseModel, VisitableBaseModel
from .rewriter import Chain, FixedPoint, RewriterBase
from .rule import ConversionRule, PrettyPrint, RewriteRule, RuleBase
from .rule import AnalysisRule, ConversionRule, PrettyPrint, RewriteRule, RuleBase
from .walk import In, Level, Post, Pre, WalkBase

__all__ = [
Expand All @@ -24,6 +25,7 @@
"PassBase",
"RewriteRule",
"ConversionRule",
"AnalysisRule",
"PrettyPrint",
"RuleBase",
"Pre",
Expand All @@ -34,4 +36,7 @@
"Chain",
"FixedPoint",
"RewriterBase",
"AnalysisResult",
"AnalysisCache",
"AnalysisRequirements",
]
84 changes: 84 additions & 0 deletions src/oqd_compiler_infrastructure/analysis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Copyright 2024-2025 Open Quantum Design

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


from __future__ import annotations

from typing import Annotated, Any, Dict, List, Tuple, Type

from pydantic import BeforeValidator, ConfigDict

########################################################################################
from oqd_compiler_infrastructure.interface import TypeReflectBaseModel

########################################################################################


def _analysis_name(value):
if isinstance(value, str):
return value
else:
return value.__class__.__name__


class AnalysisCache(TypeReflectBaseModel):
store: List[AnalysisResult] = []

def __getitem__(self, idx):
return [entry for entry in self.store if entry.name == idx]

def invalidate(self, name):
name = _analysis_name(name)

relevant_entries = filter(lambda entry: entry.valid, self[name])
for entry in relevant_entries:
entry.valid = False

def append(self, entry: AnalysisResult):
self.store.append(entry)


class AnalysisResult(TypeReflectBaseModel):
name: Annotated[str, BeforeValidator(_analysis_name)]
valid: bool = True
data: Dict[str, Any]


########################################################################################


def validate_analysis_requirement(value):
if isinstance(value, tuple):
return value
else:
return (value, Post)


class AnalysisRequirements(TypeReflectBaseModel):
model_config = ConfigDict(arbitrary_types_allowed=True)

requirements: List[
Annotated[
Tuple[Type[AnalysisRule], Type[WalkBase]],
BeforeValidator(validate_analysis_requirement),
]
] = []


########################################################################################

from oqd_compiler_infrastructure.rule import AnalysisRule # noqa: E402
from oqd_compiler_infrastructure.walk import Post, WalkBase # noqa: E402

AnalysisRequirements.model_rebuild()
Loading
Loading