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

Platform specific Readme #187

Merged
merged 20 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
4015d43
feat: implemented automatic readme generation
BrunoLiegiBastonLiegi Oct 9, 2024
2c86030
fix: fix mermaid graph
BrunoLiegiBastonLiegi Oct 9, 2024
a117d77
fix: forgot semicol...
BrunoLiegiBastonLiegi Oct 9, 2024
922c262
fix: removed space between nodes
BrunoLiegiBastonLiegi Oct 9, 2024
803a7e7
fix: trying with directed edges
BrunoLiegiBastonLiegi Oct 9, 2024
502e3bf
fix: using bidirected edges
BrunoLiegiBastonLiegi Oct 9, 2024
1d76451
fix: added nqubits and qubits
BrunoLiegiBastonLiegi Oct 9, 2024
691915d
feat: automatically retrieving the platforms
BrunoLiegiBastonLiegi Oct 9, 2024
27aec98
build: added readme generation to workflows
BrunoLiegiBastonLiegi Oct 9, 2024
ca756c7
fix: removed from workflows + minor style and bug fixes
BrunoLiegiBastonLiegi Oct 10, 2024
bd5f79b
feat: added some warnings and a reminder about generating the readmes…
BrunoLiegiBastonLiegi Oct 10, 2024
3880532
Update generate_readme.py
BrunoLiegiBastonLiegi Oct 10, 2024
e8f2dd1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 10, 2024
76e95d6
Update generate_readme.py
BrunoLiegiBastonLiegi Oct 10, 2024
492caf4
Update generate_readme.py
BrunoLiegiBastonLiegi Oct 10, 2024
8d329f3
fix: importing Path + added some docstrings
BrunoLiegiBastonLiegi Oct 10, 2024
6c2a02f
fix: fix platforms retrieval
BrunoLiegiBastonLiegi Oct 10, 2024
7a83ad0
feat: introduced argparse for specifying the platform to process
BrunoLiegiBastonLiegi Oct 11, 2024
a186562
Apply suggestions from code review
BrunoLiegiBastonLiegi Oct 11, 2024
be32893
Merge branch '0.1' into platform_readme
BrunoLiegiBastonLiegi Oct 30, 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
17 changes: 17 additions & 0 deletions .github/workflows/readme.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
on:
pull_request:
types: [opened, ready_for_review]

jobs:
comment:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v5
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'If you are changing the configuration of one or more platforms remember to run `python generate_readme.py path/to/platform ...` to update the `README.md` accordingly.'
})
122 changes: 122 additions & 0 deletions generate_readme.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
"""Small script that automatically parses some basic information from the `parameters.json` file and organizes it in a `README.md`"""

import argparse
import json
import warnings
from pathlib import Path
from typing import Union


def get_info(filename: str) -> dict:
"""Open ``filename`` and extracts: `nqubits`, `qubits`, `topology` and `native_gates`."""

with open(filename) as f:
data = json.load(f)

if not isinstance(data["topology"], list):
raise RuntimeError(
f"The topology is expected to be a list of edges (List[List[int, int]] or List[List[str, str]]), but received a {type(data['topology'])}."
)

info = {key: data[key] for key in ("nqubits", "qubits", "topology")}
one_q_native_gates = list(
next(iter(data["native_gates"]["single_qubit"].values())).keys()
)
two_q_native_gates = list(
next(iter(data["native_gates"]["two_qubit"].values())).keys()
)
info.update(
{
"native_gates": {
"single_qubit": one_q_native_gates,
"two_qubit": two_q_native_gates,
}
}
)
return info


def create_mermaid_graph(
nodes: Union[list[str], list[int]],
topology: Union[list[list[str]], list[list[int]]],
) -> str:
"""Create a markdown string encoding a mermaid graph given by the input `nodes` and `topology`."""
node_to_index = dict(zip(nodes, range(len(nodes))))
if isinstance(nodes[0], int) or nodes[0].isdecimal():
edges = "\n ".join(
[
f"{edge[0]}(({str(edge[0])})) <--> {edge[1]}(({str(edge[1])}));"
for edge in topology
]
)
else:
edges = "\n ".join(
[
f"{node_to_index[edge[0]]}(({edge[0]})) <--> {node_to_index[edge[1]]}(({edge[1]}));"
for edge in topology
]
)
markdown_str = f"""
```mermaid
---
config:
layout: elk
---
graph TD;
{edges}
```
"""
return markdown_str


def create_readme(filename: str) -> str:
"""Build the `README.md` for the input `filename`."""
info = get_info(filename)
mermaid_graph = create_mermaid_graph(info["qubits"], info["topology"])
qubits = (
", ".join([str(q) for q in info["qubits"]])
if isinstance(info["qubits"][0], int) or info["qubits"][0].isdecimal()
else ", ".join([f"{q} ({i})" for i, q in enumerate(info["qubits"])])
)
readme_str = f"""
## Native Gates
**Single Qubit**: {", ".join(info["native_gates"]["single_qubit"])}

**Two Qubit**: {", ".join(info["native_gates"]["two_qubit"])}

## Topology
**Number of qubits**: {info["nqubits"]}

**Qubits**: {qubits}
{mermaid_graph}
"""
return readme_str


if __name__ == "__main__":

parser = argparse.ArgumentParser(
prog="generate_readme",
description="Automatically generate the README.md for the given input platform/s.",
)
parser.add_argument("platform", nargs="+", type=Path)
platforms = parser.parse_args().platform

for platform in platforms:

filename = platform / "parameters.json"
try:
readme_str = create_readme(filename)
except FileNotFoundError:
warnings.warn(
f"Couldn't find ``{filename}``, unable to generate the README for platform ``{platform}``."
)
continue
except RuntimeError as err:
warnings.warn(
err.args[0]
+ f" Unable to generate the README for platform ``{platform}``."
)
continue

(platform / "README.md").write_text(f"# {platform}\n{readme_str}")
41 changes: 41 additions & 0 deletions qw11q/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# qw11q

## Native Gates
**Single Qubit**: RX, RX12, MZ

**Two Qubit**: CZ, iSWAP

## Topology
**Number of qubits**: 16

**Qubits**: A1 (0), A2 (1), A3 (2), A4 (3), A5 (4), A6 (5), B1 (6), B2 (7), B3 (8), B4 (9), B5 (10), D1 (11), D2 (12), D3 (13), D4 (14), D5 (15)

```mermaid
---
config:
layout: elk
---
graph TD;
0((A1)) <--> 1((A2));
0((A1)) <--> 2((A3));
0((A1)) <--> 15((D5));
1((A2)) <--> 3((A4));
1((A2)) <--> 5((A6));
2((A3)) <--> 3((A4));
2((A3)) <--> 14((D4));
3((A4)) <--> 4((A5));
3((A4)) <--> 8((B3));
4((A5)) <--> 6((B1));
5((A6)) <--> 8((B3));
5((A6)) <--> 13((D3));
6((B1)) <--> 7((B2));
6((B1)) <--> 8((B3));
7((B2)) <--> 9((B4));
8((B3)) <--> 9((B4));
9((B4)) <--> 10((B5));
11((D1)) <--> 12((D2));
11((D1)) <--> 13((D3));
12((D2)) <--> 14((D4));
13((D3)) <--> 14((D4));
14((D4)) <--> 15((D5));
```
23 changes: 23 additions & 0 deletions qw5q_platinum/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# qw5q_platinum

## Native Gates
**Single Qubit**: RX, RX12, MZ

**Two Qubit**: CZ

## Topology
**Number of qubits**: 5

**Qubits**: 0, 1, 2, 3, 4

```mermaid
---
config:
layout: elk
---
graph TD;
0((0)) <--> 2((2));
1((1)) <--> 2((2));
2((2)) <--> 3((3));
2((2)) <--> 4((4));
```
Loading