Skip to content

Commit 0167a89

Browse files
Merge pull request #58 from ColibrITD-SAS/feat-doc-abc
specify in the doc of each ABC that it should not be instantiated directly
2 parents 986c885 + e846e86 commit 0167a89

File tree

7 files changed

+38
-20
lines changed

7 files changed

+38
-20
lines changed

CONTRIBUTING.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ following (even though each of these sections is optional):
125125
2. `Returns`
126126
3. `Raises`
127127
4. `Example(s)`
128-
5. `Notes`
129-
6. `Warnings`
128+
5. `Note`
129+
6. `Warning`
130130

131131
### When you're done
132132

docs/_static/custom.js

+23-5
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,25 @@ window.onload = () => {
9292
});
9393
ngListLocation.innerHTML = ngLinks;
9494
}
95-
};
9695

97-
// const themeButton = document.querySelector('themeSwitcher')
98-
// themeButton.addEventListener('click', () => {
99-
//
100-
// });
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 class="highlighted">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+
};
101114

102115
function getEndOfClassHeader(elt) {
103116
admonition = elt.querySelectorAll(".admonition");
@@ -109,6 +122,11 @@ function getEndOfClassHeader(elt) {
109122
return elt;
110123
}
111124

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

mpqp/core/instruction/gates/gate.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ def inverse(self) -> Gate:
335335

336336
@typechecked
337337
class SingleQubitGate(Gate, ABC):
338-
"""Gates operating on a single qubit.
338+
"""Abstract class for gates operating on a single qubit.
339339
340340
Args:
341341
target: Index or referring to the qubit on which the gate will be applied.

mpqp/core/instruction/gates/gate_definition.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
@typechecked
1919
class GateDefinition(ABC):
20-
"""A class used to handle the definition of a Gate.
20+
"""Abstract class used to handle the definition of a Gate.
2121
2222
A quantum gate can be defined in several ways, and this class allows us to
2323
define it as we prefer. It also handles the translation from one definition

mpqp/core/instruction/gates/native_gates.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def _qiskit_parameter_adder(
8787
class NativeGate(Gate, SimpleClassReprABC):
8888
"""The standard on which we rely, OpenQASM, comes with a set of gates
8989
supported by default. More complicated gates can be defined by the user.
90-
This class represent all those gates supported by default.
90+
This abstract class represent all those gates supported by default.
9191
9292
Args:
9393
targets: List of indices referring to the qubits on which the gate will
@@ -102,9 +102,9 @@ class NativeGate(Gate, SimpleClassReprABC):
102102
class RotationGate(NativeGate, ParametrizedGate, SimpleClassReprABC):
103103
"""Many gates can be classified as a simple rotation gate, around a specific
104104
axis (and potentially with a control qubit). All those gates have in common
105-
a single parameter: ``theta``. This class help up factorize this behavior,
106-
and simply having to tweak the matrix semantics and qasm translation of
107-
the specific gate.
105+
a single parameter: ``theta``. This abstract class helps up factorize this
106+
behavior, and simply having to tweak the matrix semantics and qasm
107+
translation of the specific gate.
108108
109109
Args:
110110
theta: Angle of the rotation.
@@ -169,7 +169,7 @@ def to_other_language(
169169

170170
@typechecked
171171
class NoParameterGate(NativeGate, SimpleClassReprABC):
172-
"""Class describing native gates that do not depend on parameters.
172+
"""Abstract class describing native gates that do not depend on parameters.
173173
174174
Args:
175175
targets: List of indices referring to the qubits on which the gate will
@@ -255,7 +255,8 @@ def to_matrix(self) -> Matrix:
255255

256256
@typechecked
257257
class OneQubitNoParamGate(SingleQubitGate, NoParameterGate, SimpleClassReprABC):
258-
"""Class describing one-qubit native gates that do not depend on parameters.
258+
"""Abstract Class describing one-qubit native gates that do not depend on
259+
parameters.
259260
260261
Args:
261262
target: Index referring to the qubits on which the gate will be applied.

mpqp/core/instruction/gates/parametrized_gate.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@
3131

3232
@typechecked
3333
class ParametrizedGate(Gate, ABC):
34-
"""Abstract class to factorize behavior of parametrized gate. Since it's an
35-
abstract class, do not instantiate one yourself.
34+
"""Abstract class to factorize behavior of parametrized gate.
3635
3736
Args:
3837
definition: Provide a definition of the gate (matrix, gate combination,

mpqp/core/instruction/measurement/measure.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
from abc import ABC
1414
from typing import Optional
1515

16-
from typeguard import typechecked, TypeCheckError
16+
from typeguard import TypeCheckError, typechecked
1717

1818
from mpqp.core.instruction import Instruction
1919

2020

2121
@typechecked
2222
class Measure(Instruction, ABC):
23-
"""Class representing a generic measure of quantum state generated by a
24-
quantum circuit.
23+
"""Abstract class representing the measurement of the quantum state
24+
generated by a quantum circuit.
2525
2626
This class is used to regroup attributes and methods shared by all different
2727
types of measures.

0 commit comments

Comments
 (0)