Skip to content

Commit 6eeec20

Browse files
Merge pull request #62 from ColibrITD-SAS/dev
New minor version, with it's flow of buxfixes
2 parents ae8da66 + 971d97c commit 6eeec20

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+1122
-479
lines changed

.github/workflows/tests.yml

+29-12
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,57 @@ on:
44
push:
55
branches:
66
- dev
7+
- main
78
workflow_dispatch:
89
inputs:
910
python_v:
10-
description: 'python version'
11+
description: "python version"
1112
required: true
12-
default: '3.9'
13+
default: "3.9"
1314
type: choice
1415
options:
15-
- '3.9'
16-
- '3.10'
17-
- '3.11'
16+
- "3.9"
17+
- "3.10"
18+
- "3.11"
1819
commit_ref:
1920
description: Specific ref (branch, tag or SHA)
20-
default: ''
21+
default: ""
2122
type: string
2223
required: false
23-
24+
long:
25+
description: "Run long tests"
26+
required: false
27+
default: false
28+
type: boolean
2429

2530
jobs:
2631
test:
2732
runs-on: ubuntu-latest
2833
steps:
29-
- name: Checkout Repository
34+
- name: Checkout repository
3035
uses: actions/checkout@v4
3136
with:
3237
ref: ${{ github.event.inputs.commit_ref || github.ref }}
33-
- name: Set up Python ${{ github.event.inputs.python_v || '3.9' }}
38+
- name: Set up python ${{ github.event.inputs.python_v || '3.9' }}
3439
uses: actions/setup-python@v5
3540
with:
3641
python-version: ${{ github.event.inputs.python_v || '3.9' }}
3742
cache: "pip"
38-
- name: Install Dependencies
43+
- name: Install dependencies
3944
run: |
4045
pip install --upgrade pip
4146
pip install -r requirements-dev.txt
42-
- name: Run test
43-
run: python -m pytest
47+
- name: Install long dedendencies
48+
if: ${{ github.event.inputs.long == 'true' || github.ref_name == 'main' }}
49+
run: |
50+
pip install .
51+
sudo apt-get update
52+
sudo apt install -y poppler-utils
53+
sudo apt-get install -y texlive-latex-base texlive-pictures texlive-latex-extra
54+
- name: Run tests
55+
run: |
56+
if [ "${{ github.event.inputs.long }}" == "true" ] || [ "${{ github.ref_name }}" == "main" ]; then
57+
python -m pytest --long-local
58+
else
59+
python -m pytest
60+
fi

CONTRIBUTING.md

+16-8
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describing the problem you would like to solve.
1818

1919
### Setup your environment locally
2020

21-
_Some commands will assume you have the GitHub CLI installed, if you haven't,
21+
\_Some commands will assume you have the GitHub CLI installed, if you haven't,
2222
consider [installing it](https://github.com/cli/cli#installation), but you can
2323
always use the Web UI if you prefer that instead.
2424

@@ -41,6 +41,13 @@ etc... included), use pip:
4141
pip install -r requirements-dev.txt
4242
```
4343

44+
In the documentation, some notebooks are rendered to HTML, this process is done
45+
using [Pandoc](https://pandoc.org/). Unfortunately, this software cannot be
46+
installed from the pip repository, so you need to install it separately. You can
47+
check [their documentation](https://pandoc.org/installing.html) to see how to
48+
install it on your OS (you can find it on most package manager: `apt`,
49+
`yum`, `pacman`, `choco`, `winget`, `brew` and more... )
50+
4451
The last (optinal) step is to setup a GitHub personal access tokens to enable
4552
the sphinx automatic changelog generation. This step is only important if you
4653
want to preview this changelog generation on your personal computer. Not being
@@ -88,11 +95,12 @@ repository, and find the one you need to modify to achieve your goal.
8895

8996
Here are some useful scripts for when you are developing:
9097

91-
| Command | Description |
92-
| --------------------------------- | ------------------------ |
93-
| `sphinx-build -b html docs build` | Builds the documentation |
94-
| `python -m pytest` | Runs the test suite |
95-
| `python -m pytest --long` | Runs the long tests too |
98+
| Command | Description |
99+
| --------------------------------- | ------------------------- |
100+
| `sphinx-build -b html docs build` | Builds the documentation |
101+
| `python -m pytest` | Runs the test suite |
102+
| `python -m pytest --long` | Runs the long tests too |
103+
| `python -m pytest --long-local` | Runs the local long tests |
96104

97105
When making commits, make sure to follow the
98106
[conventional commit](https://www.conventionalcommits.org/en/v1.0.0/)
@@ -117,8 +125,8 @@ following (even though each of these sections is optional):
117125
2. `Returns`
118126
3. `Raises`
119127
4. `Example(s)`
120-
5. `Notes`
121-
6. `Warnings`
128+
5. `Note`
129+
6. `Warning`
122130

123131
### When you're done
124132

Dockerfile

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ RUN pip3 install --upgrade pip && \
99

1010
FROM python:3.9
1111

12-
RUN apt-get update && \
13-
apt-get install -y pandoc && \
14-
apt-get clean && \
12+
RUN apt update && \
13+
apt install -y pandoc && \
14+
apt clean && \
1515
rm -rf /var/lib/apt/lists/*
1616

1717
WORKDIR /usr/src/app/mpqp

conftest.py

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
import os
2-
3-
from pytest import Metafunc, Parser
1+
from pytest import Parser
42

53

64
def pytest_addoption(parser: Parser):
75
parser.addoption("--long", action="store_false", help="If set, long tests will run")
8-
9-
10-
def pytest_generate_tests(metafunc: Metafunc):
11-
print("ho")
12-
if metafunc.config.option.long:
13-
os.environ["LONG_TESTS"] = "True"
6+
parser.addoption(
7+
"--long-local",
8+
action="store_false",
9+
help="If set, only local long tests will run",
10+
)

docs/_static/custom.css

+50
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ div.document {
2929
} */
3030

3131
/* *** fix for rtd dark *** */
32+
html[data-theme="dark"] .theme-switcher {
33+
box-shadow: 0px 1px 14px 2px rgb(255 255 255 / 20%);
34+
}
3235

3336
html[data-theme="dark"] div.nboutput.container div.output_area.stderr {
3437
background: rgb(103, 23, 23);
@@ -159,3 +162,50 @@ html[data-theme="dark"] .rst-content .admonition,
159162
html[data-theme="dark"] .rst-content .note {
160163
background-color: #80cb53;
161164
}*/
165+
166+
.highlight-python.import {
167+
position: sticky;
168+
top: 10px;
169+
z-index: 9999;
170+
box-shadow: 0px 0px 10px 0px black;
171+
}
172+
173+
html[data-theme="dark"] .highlight-python.import {
174+
box-shadow: 0px 0px 10px 0px #595959;
175+
}
176+
177+
html[data-theme="dark"] .rst-content .highlighted {
178+
background: #7e6500;
179+
box-shadow: 0 0 0 2px #7e6500;
180+
}
181+
182+
#native-gates-list > * {
183+
position: relative;
184+
}
185+
186+
#native-gates-list {
187+
display: flex;
188+
flex-wrap: wrap;
189+
margin-block-end: 1em;
190+
position: sticky;
191+
top: 57px;
192+
z-index: 10000;
193+
background-color: #141414;
194+
}
195+
196+
#native-gates-list > * {
197+
padding: 0 1em 0 1em;
198+
border: 0.5px solid;
199+
border-block-start: 0;
200+
border-block-end: 0;
201+
border-color: black;
202+
margin-block-end: 0.5em;
203+
}
204+
205+
html[data-theme="dark"] #native-gates-list > * {
206+
border-color: white;
207+
}
208+
209+
section > * {
210+
scroll-padding-block-start: 60px;
211+
}

docs/_static/custom.js

+39-5
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,41 @@ window.onload = () => {
7676
}
7777
}
7878
});
79-
};
8079

81-
// const themeButton = document.querySelector('themeSwitcher')
82-
// themeButton.addEventListener('click', () => {
83-
//
84-
// });
80+
// in the native gates section, add the list of native gates
81+
ngListLocation = document.getElementById("native-gates-list");
82+
if (ngListLocation) {
83+
ngSection = ngListLocation.parentElement;
84+
ngClasses = ngSection.querySelectorAll("dl.py.class");
85+
ngLinks = "";
86+
87+
ngClasses.forEach(function (c) {
88+
if (c.textContent.includes("ABC")) return;
89+
ngLinks += `<a href="#${c.querySelector("dt.sig.sig-object.py").id}">
90+
${c.querySelector("span.descname").innerText}
91+
</a>`;
92+
});
93+
ngListLocation.innerHTML = ngLinks;
94+
}
95+
96+
// we add a note for abstract classes to remind that they cannot be
97+
// implemented directly
98+
document.querySelectorAll(".class").forEach((class_elt) => {
99+
if (isABC(class_elt)) {
100+
parents = class_elt.querySelector("dd > p:first-child");
101+
template = document.createElement("template");
102+
template.innerHTML = `
103+
<div class="admonition note">
104+
<p class="admonition-title"><span>Note</span></p>
105+
<p>
106+
Abstract classes (ABCs) are not meant to be instantiated as is. See
107+
classes that inherite from this one to check how to instantiate it.
108+
</p>
109+
</div>`;
110+
parents.insertAdjacentElement("afterend", template.content.children[0]);
111+
}
112+
});
113+
};
85114

86115
function getEndOfClassHeader(elt) {
87116
admonition = elt.querySelectorAll(".admonition");
@@ -93,6 +122,11 @@ function getEndOfClassHeader(elt) {
93122
return elt;
94123
}
95124

125+
function isABC(elt) {
126+
parents = elt.querySelector("dd > p:first-child");
127+
return parents && parents.innerHTML.includes("ABC");
128+
}
129+
96130
function isEnum(elt, explored = []) {
97131
id = elt.querySelector("dt").id;
98132
if (explored.includes(id)) return false;

docs/barrier.rst

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Barriers
22
========
33

44
.. code-block:: python
5+
:class: import
56
67
from mpqp import Barrier
78

docs/circuit.rst

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ The Quantum Circuit
22
===================
33

44
.. code-block:: python
5+
:class: import
56
67
from mpqp import QCircuit
78

docs/execution.rst

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Execution
22
=========
33

44
.. code-block:: python
5+
:class: import
56
67
from mpqp.execution import *
78

docs/gates.rst

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Gates
22
=====
33

44
.. code-block:: python
5+
:class: import
56
67
from mpqp.gates import *
78

docs/measures.rst

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Measurements
22
============
33

44
.. code-block:: python
5+
:class: import
56
67
from mpqp.measures import *
78

docs/noise.rst

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ details about the manipulation, usage, and simulation of noise models are
1414
presented.
1515

1616
.. code-block:: python
17+
:class: import
1718
1819
from mpqp.noise import *
1920

docs/qasm.rst

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ QASM converter
22
==================
33

44
.. code-block:: python
5+
:class: import
56
67
from mpqp.qasm import *
78

docs/tools.rst

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Useful Maths Operations
1313
-----------------------
1414

1515
.. code-block:: python
16+
:class: import
1617
1718
from mpqp.tools.maths import *
1819
@@ -22,6 +23,7 @@ Generics
2223
--------
2324

2425
.. code-block:: python
26+
:class: import
2527
2628
from mpqp.tools.generics import *
2729
@@ -31,6 +33,7 @@ Errors
3133
------
3234

3335
.. code-block:: python
36+
:class: import
3437
3538
from mpqp.tools.errors import *
3639
@@ -40,6 +43,7 @@ Choice Tree
4043
-----------
4144

4245
.. code-block:: python
46+
:class: import
4347
4448
from mpqp.tools.choice_tree import *
4549

docs/vqa.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Variational Quantum Algorithms
44
==============================
55

66
.. code-block:: python
7+
:class: import
78
89
from mpqp.execution.vqa import *
910
@@ -16,7 +17,7 @@ value attributed. It can be created as such:
1617

1718
.. code-block:: python
1819
19-
from mpqp.execution.vqa import symbols
20+
from sympy import symbols
2021
2122
theta, k = symbols("Θ k")
2223

examples/notebooks/1_Basics_of_circuit.ipynb

+2-2
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@
649649
"metadata": {},
650650
"outputs": [],
651651
"source": [
652-
"from mpqp.gates import symbols\n",
652+
"from sympy import symbols\n",
653653
"\n",
654654
"theta, k = symbols(\"θ k\")"
655655
]
@@ -790,7 +790,7 @@
790790
"name": "python",
791791
"nbconvert_exporter": "python",
792792
"pygments_lexer": "ipython3",
793-
"version": "3.9.12"
793+
"version": "3.9.5"
794794
}
795795
},
796796
"nbformat": 4,

0 commit comments

Comments
 (0)