Skip to content

Commit 381a8d9

Browse files
ElePTmtreinish
andauthored
Expand docstrings for annotated flag on control() and inverse() (#11749)
* Add annotated * Add returns * Co-authored-by: Matthew Treinish <mtreinish@kortar.org> Apply suggestions from Matt's code review Co-authored-by: Matthew Treinish <mtreinish@kortar.org> * Format suggestions * Fix lint * Apply last round of suggestions Co-authored-by: Matthew Treinish <mtreinish@kortar.org> --------- Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
1 parent cf0958d commit 381a8d9

28 files changed

+637
-143
lines changed

qiskit/circuit/library/generalized_gates/unitary.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def __init__(
7474
7575
Args:
7676
data: Unitary operator.
77-
label: Unitary name for backend [Default: None].
77+
label: Unitary name for backend [Default: ``None``].
7878
check_input: If set to ``False`` this asserts the input
7979
is known to be unitary and the checking to validate this will
8080
be skipped. This should only ever be used if you know the

qiskit/circuit/library/hamiltonian_gate.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def __init__(
5252
Args:
5353
data: A hermitian operator.
5454
time: Time evolution parameter.
55-
label: Unitary name for backend [Default: None].
55+
label: Unitary name for backend [Default: ``None``].
5656
5757
Raises:
5858
ValueError: if input data is not an N-qubit unitary operator.

qiskit/circuit/library/standard_gates/ecr.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,17 @@ def _define(self):
110110
self.definition = qc
111111

112112
def inverse(self, annotated: bool = False):
113-
"""Return inverse ECR gate (itself)."""
113+
"""Return inverse ECR gate (itself).
114+
115+
Args:
116+
annotated: when set to ``True``, this is typically used to return an
117+
:class:`.AnnotatedOperation` with an inverse modifier set instead of a concrete
118+
:class:`.Gate`. However, for this class this argument is ignored as this gate
119+
is self-inverse.
120+
121+
Returns:
122+
ECRGate: inverse gate (self-inverse).
123+
"""
114124
return ECRGate() # self-inverse
115125

116126
def __eq__(self, other):

qiskit/circuit/library/standard_gates/global_phase.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,19 @@ def _define(self):
5353
self.definition = qc
5454

5555
def inverse(self, annotated: bool = False):
56-
r"""Return inverted GlobalPhaseGate gate.
56+
r"""Return inverse GlobalPhaseGate gate.
5757
5858
:math:`\text{GlobalPhaseGate}(\lambda)^{\dagger} = \text{GlobalPhaseGate}(-\lambda)`
59+
60+
Args:
61+
annotated: when set to ``True``, this is typically used to return an
62+
:class:`.AnnotatedOperation` with an inverse modifier set instead of a concrete
63+
:class:`.Gate`. However, for this class this argument is ignored as the inverse
64+
is always another :class:`.GlobalPhaseGate` with an inverted
65+
parameter value.
66+
67+
Returns:
68+
GlobalPhaseGate: inverse gate.
5969
"""
6070
return GlobalPhaseGate(-self.params[0])
6171

qiskit/circuit/library/standard_gates/h.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ def control(
8585
One control qubit returns a CH gate.
8686
8787
Args:
88-
num_ctrl_qubits (int): number of control qubits.
89-
label (str or None): An optional label for the gate [Default: None]
90-
ctrl_state (int or str or None): control state expressed as integer,
91-
string (e.g. '110'), or None. If None, use all 1s.
88+
num_ctrl_qubits: number of control qubits.
89+
label: An optional label for the gate [Default: ``None``]
90+
ctrl_state: control state expressed as integer,
91+
string (e.g.``'110'``), or ``None``. If ``None``, use all 1s.
9292
annotated: indicates whether the controlled gate can be implemented
9393
as an annotated gate.
9494
@@ -107,7 +107,17 @@ def control(
107107
return gate
108108

109109
def inverse(self, annotated: bool = False):
110-
r"""Return inverted H gate (itself)."""
110+
r"""Return inverted H gate (itself).
111+
112+
Args:
113+
annotated: when set to ``True``, this is typically used to return an
114+
:class:`.AnnotatedOperation` with an inverse modifier set instead of a concrete
115+
:class:`.Gate`. However, for this class this argument is ignored as this gate
116+
is self-inverse.
117+
118+
Returns:
119+
HGate: inverse gate (self-inverse).
120+
"""
111121
return HGate() # self-inverse
112122

113123
def __eq__(self, other):

qiskit/circuit/library/standard_gates/i.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,17 @@ def __init__(self, label: Optional[str] = None, *, duration=None, unit="dt"):
5252
_singleton_lookup_key = stdlib_singleton_key()
5353

5454
def inverse(self, annotated: bool = False):
55-
"""Invert this gate."""
55+
"""Returne the inverse gate (itself).
56+
57+
Args:
58+
annotated: when set to ``True``, this is typically used to return an
59+
:class:`.AnnotatedOperation` with an inverse modifier set instead of a concrete
60+
:class:`.Gate`. However, for this class this argument is ignored as this gate
61+
is self-inverse.
62+
63+
Returns:
64+
IGate: inverse gate (self-inverse).
65+
."""
5666
return IGate() # self-inverse
5767

5868
def power(self, exponent: float):

qiskit/circuit/library/standard_gates/p.py

+23-13
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ def control(
101101
"""Return a (multi-)controlled-Phase gate.
102102
103103
Args:
104-
num_ctrl_qubits (int): number of control qubits.
105-
label (str or None): An optional label for the gate [Default: None]
106-
ctrl_state (int or str or None): control state expressed as integer,
107-
string (e.g. '110'), or None. If None, use all 1s.
104+
num_ctrl_qubits: number of control qubits.
105+
label: An optional label for the gate [Default: ``None``]
106+
ctrl_state: control state expressed as integer,
107+
string (e.g. ``'110'``), or ``None``. If ``None``, use all 1s.
108108
annotated: indicates whether the controlled gate can be implemented
109109
as an annotated gate.
110110
@@ -127,7 +127,17 @@ def control(
127127
return gate
128128

129129
def inverse(self, annotated: bool = False):
130-
r"""Return inverted Phase gate (:math:`Phase(\lambda)^{\dagger} = Phase(-\lambda)`)"""
130+
r"""Return inverted Phase gate (:math:`Phase(\lambda)^{\dagger} = Phase(-\lambda)`)
131+
132+
Args:
133+
annotated: when set to ``True``, this is typically used to return an
134+
:class:`.AnnotatedOperation` with an inverse modifier set instead of a concrete
135+
:class:`.Gate`. However, for this class this argument is ignored as the inverse
136+
of this gate is always another :class:`.PGate` with an inverse parameter value.
137+
138+
Returns:
139+
PGate: inverse gate.
140+
"""
131141
return PhaseGate(-self.params[0])
132142

133143
def __array__(self, dtype=None):
@@ -244,10 +254,10 @@ def control(
244254
"""Controlled version of this gate.
245255
246256
Args:
247-
num_ctrl_qubits (int): number of control qubits.
248-
label (str or None): An optional label for the gate [Default: None]
249-
ctrl_state (int or str or None): control state expressed as integer,
250-
string (e.g. '110'), or None. If None, use all 1s.
257+
num_ctrl_qubits: number of control qubits.
258+
label: An optional label for the gate [Default: ``None``]
259+
ctrl_state: control state expressed as integer,
260+
string (e.g.``'110'``), or ``None``. If ``None``, use all 1s.
251261
annotated: indicates whether the controlled gate can be implemented
252262
as an annotated gate.
253263
@@ -370,10 +380,10 @@ def control(
370380
"""Controlled version of this gate.
371381
372382
Args:
373-
num_ctrl_qubits (int): number of control qubits.
374-
label (str or None): An optional label for the gate [Default: None]
375-
ctrl_state (int or str or None): control state expressed as integer,
376-
string (e.g. '110'), or None. If None, use all 1s.
383+
num_ctrl_qubits: number of control qubits.
384+
label: An optional label for the gate [Default: ``None``]
385+
ctrl_state: control state expressed as integer,
386+
string (e.g.``'110'``), or ``None``. If ``None``, use all 1s.
377387
annotated: indicates whether the controlled gate can be implemented
378388
as an annotated gate.
379389

qiskit/circuit/library/standard_gates/r.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,16 @@ def _define(self):
8080
self.definition = qc
8181

8282
def inverse(self, annotated: bool = False):
83-
"""Invert this gate.
83+
"""Invert this gate as: :math:`r(θ, φ)^dagger = r(-θ, φ)`
8484
85-
r(θ, φ)^dagger = r(-θ, φ)
85+
Args:
86+
annotated: when set to ``True``, this is typically used to return an
87+
:class:`.AnnotatedOperation` with an inverse modifier set instead of a concrete
88+
:class:`.Gate`. However, for this class this argument is ignored as the inverse
89+
of this gate is always a :class:`.RGate` with an inverted parameter value.
90+
91+
Returns:
92+
RGate: inverse gate.
8693
"""
8794
return RGate(-self.params[0], self.params[1])
8895

qiskit/circuit/library/standard_gates/rx.py

+24-5
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ def control(
8282
"""Return a (multi-)controlled-RX gate.
8383
8484
Args:
85-
num_ctrl_qubits (int): number of control qubits.
86-
label (str or None): An optional label for the gate [Default: None]
87-
ctrl_state (int or str or None): control state expressed as integer,
88-
string (e.g. '110'), or None. If None, use all 1s.
85+
num_ctrl_qubits: number of control qubits.
86+
label: An optional label for the gate [Default: ``None``]
87+
ctrl_state: control state expressed as integer,
88+
string (e.g.``'110'``), or ``None``. If ``None``, use all 1s.
8989
annotated: indicates whether the controlled gate can be implemented
9090
as an annotated gate.
9191
@@ -108,6 +108,15 @@ def inverse(self, annotated: bool = False):
108108
r"""Return inverted RX gate.
109109
110110
:math:`RX(\lambda)^{\dagger} = RX(-\lambda)`
111+
112+
Args:
113+
annotated: when set to ``True``, this is typically used to return an
114+
:class:`.AnnotatedOperation` with an inverse modifier set instead of a concrete
115+
:class:`.Gate`. However, for this class this argument is ignored as the inverse
116+
of this gate is always a :class:`.RXGate` with an inverted parameter value.
117+
118+
Returns:
119+
RXGate: inverse gate.
111120
"""
112121
return RXGate(-self.params[0])
113122

@@ -242,7 +251,17 @@ def _define(self):
242251
self.definition = qc
243252

244253
def inverse(self, annotated: bool = False):
245-
"""Return inverse CRX gate (i.e. with the negative rotation angle)."""
254+
"""Return inverse CRX gate (i.e. with the negative rotation angle).
255+
256+
Args:
257+
annotated: when set to ``True``, this is typically used to return an
258+
:class:`.AnnotatedOperation` with an inverse modifier set instead of a concrete
259+
:class:`.Gate`. However, for this class this argument is ignored as the inverse
260+
of this gate is always a :class:`.CRXGate` with an inverted parameter value.
261+
262+
Returns:
263+
CRXGate: inverse gate.
264+
"""
246265
return CRXGate(-self.params[0], ctrl_state=self.ctrl_state)
247266

248267
def __array__(self, dtype=None):

qiskit/circuit/library/standard_gates/rxx.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,17 @@ def _define(self):
109109
self.definition = qc
110110

111111
def inverse(self, annotated: bool = False):
112-
"""Return inverse RXX gate (i.e. with the negative rotation angle)."""
112+
"""Return inverse RXX gate (i.e. with the negative rotation angle).
113+
114+
Args:
115+
annotated: when set to ``True``, this is typically used to return an
116+
:class:`.AnnotatedOperation` with an inverse modifier set instead of a concrete
117+
:class:`.Gate`. However, for this class this argument is ignored as the inverse
118+
of this gate is always a :class:`.RXXGate` with an inverted parameter value.
119+
120+
Returns:
121+
RXXGate: inverse gate.
122+
"""
113123
return RXXGate(-self.params[0])
114124

115125
def __array__(self, dtype=None):

qiskit/circuit/library/standard_gates/ry.py

+25-6
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ def control(
8181
"""Return a (multi-)controlled-RY gate.
8282
8383
Args:
84-
num_ctrl_qubits (int): number of control qubits.
85-
label (str or None): An optional label for the gate [Default: None]
86-
ctrl_state (int or str or None): control state expressed as integer,
87-
string (e.g. '110'), or None. If None, use all 1s.
84+
num_ctrl_qubits: number of control qubits.
85+
label: An optional label for the gate [Default: ``None``]
86+
ctrl_state: control state expressed as integer,
87+
string (e.g.``'110'``), or ``None``. If ``None``, use all 1s.
8888
annotated: indicates whether the controlled gate can be implemented
8989
as an annotated gate.
9090
@@ -104,9 +104,18 @@ def control(
104104
return gate
105105

106106
def inverse(self, annotated: bool = False):
107-
r"""Return inverted RY gate.
107+
r"""Return inverse RY gate.
108108
109109
:math:`RY(\lambda)^{\dagger} = RY(-\lambda)`
110+
111+
Args:
112+
annotated: when set to ``True``, this is typically used to return an
113+
:class:`.AnnotatedOperation` with an inverse modifier set instead of a concrete
114+
:class:`.Gate`. However, for this class this argument is ignored as the inverse
115+
of this gate is always a :class:`.RYGate` with an inverted parameter value.
116+
117+
Returns:
118+
RYGate: inverse gate.
110119
"""
111120
return RYGate(-self.params[0])
112121

@@ -237,7 +246,17 @@ def _define(self):
237246
self.definition = qc
238247

239248
def inverse(self, annotated: bool = False):
240-
"""Return inverse CRY gate (i.e. with the negative rotation angle)."""
249+
"""Return inverse CRY gate (i.e. with the negative rotation angle)
250+
251+
Args:
252+
annotated: when set to ``True``, this is typically used to return an
253+
:class:`.AnnotatedOperation` with an inverse modifier set instead of a concrete
254+
:class:`.Gate`. However, for this class this argument is ignored as the inverse
255+
of this gate is always a :class:`.CRYGate` with an inverted parameter value.
256+
257+
Returns:
258+
CRYGate: inverse gate.
259+
."""
241260
return CRYGate(-self.params[0], ctrl_state=self.ctrl_state)
242261

243262
def __array__(self, dtype=None):

qiskit/circuit/library/standard_gates/ryy.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,17 @@ def _define(self):
109109
self.definition = qc
110110

111111
def inverse(self, annotated: bool = False):
112-
"""Return inverse RYY gate (i.e. with the negative rotation angle)."""
112+
"""Return inverse RYY gate (i.e. with the negative rotation angle).
113+
114+
Args:
115+
annotated: when set to ``True``, this is typically used to return an
116+
:class:`.AnnotatedOperation` with an inverse modifier set instead of a concrete
117+
:class:`.Gate`. However, for this class this argument is ignored as the inverse
118+
of this gate is always a :class:`.RYYGate` with an inverted parameter value.
119+
120+
Returns:
121+
RYYGate: inverse gate.
122+
"""
113123
return RYYGate(-self.params[0])
114124

115125
def __array__(self, dtype=None):

qiskit/circuit/library/standard_gates/rz.py

+24-5
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@ def control(
9292
"""Return a (multi-)controlled-RZ gate.
9393
9494
Args:
95-
num_ctrl_qubits (int): number of control qubits.
96-
label (str or None): An optional label for the gate [Default: None]
97-
ctrl_state (int or str or None): control state expressed as integer,
98-
string (e.g. '110'), or None. If None, use all 1s.
95+
num_ctrl_qubits: number of control qubits.
96+
label: An optional label for the gate [Default: ``None``]
97+
ctrl_state: control state expressed as integer,
98+
string (e.g.``'110'``), or ``None``. If ``None``, use all 1s.
9999
annotated: indicates whether the controlled gate can be implemented
100100
as an annotated gate.
101101
@@ -118,6 +118,15 @@ def inverse(self, annotated: bool = False):
118118
r"""Return inverted RZ gate
119119
120120
:math:`RZ(\lambda)^{\dagger} = RZ(-\lambda)`
121+
122+
Args:
123+
annotated: when set to ``True``, this is typically used to return an
124+
:class:`.AnnotatedOperation` with an inverse modifier set instead of a concrete
125+
:class:`.Gate`. However, for this class this argument is ignored as the inverse
126+
of this gate is always a :class:`.RZGate` with an inverted parameter value.
127+
128+
Returns:
129+
RZGate: inverse gate.
121130
"""
122131
return RZGate(-self.params[0])
123132

@@ -255,7 +264,17 @@ def _define(self):
255264
self.definition = qc
256265

257266
def inverse(self, annotated: bool = False):
258-
"""Return inverse CRZ gate (i.e. with the negative rotation angle)."""
267+
"""Return inverse CRZ gate (i.e. with the negative rotation angle).
268+
269+
Args:
270+
annotated: when set to ``True``, this is typically used to return an
271+
:class:`.AnnotatedOperation` with an inverse modifier set instead of a concrete
272+
:class:`.Gate`. However, for this class this argument is ignored as the inverse
273+
of this gate is always a :class:`.CRZGate` with an inverted parameter value.
274+
275+
Returns:
276+
CRZGate: inverse gate.
277+
"""
259278
return CRZGate(-self.params[0], ctrl_state=self.ctrl_state)
260279

261280
def __array__(self, dtype=None):

0 commit comments

Comments
 (0)