Skip to content

Commit ef98271

Browse files
authored
Approve functions used as default arguments (#4699)
* Approve functions used as default argumenets * The default value for **seed** is the result of a function call The default value for **seed** is the result of a function call which is not normally recommended and causes flake8-bugbear to raise a B008 error. However, in this case, it is accptable because `LinearCongruentialGenerator.__init__()` will only be called once per instance and it ensures that each instance will generate a unique sequence of numbers. * The default value for **backend** is the result of a function call The default value for **backend** is the result of a function call which is not normally recommended and causes flake8-bugbear to raise a B008 error. However, in this case, it is accptable because `Aer.get_backend()` is called when the function is definition and that same backend is then reused for function calls. * Update linear_congruential_generator.py * Update ripple_adder_classic.py * Update ripple_adder_classic.py * Update ripple_adder_classic.py * Update ripple_adder_classic.py * Update ripple_adder_classic.py
1 parent 097f830 commit ef98271

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

Diff for: other/linear_congruential_generator.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ class LinearCongruentialGenerator:
88
A pseudorandom number generator.
99
"""
1010

11-
def __init__(self, multiplier, increment, modulo, seed=int(time())):
11+
# The default value for **seed** is the result of a function call which is not
12+
# normally recommended and causes flake8-bugbear to raise a B008 error. However,
13+
# in this case, it is accptable because `LinearCongruentialGenerator.__init__()`
14+
# will only be called once per instance and it ensures that each instance will
15+
# generate a unique sequence of numbers.
16+
17+
def __init__(self, multiplier, increment, modulo, seed=int(time())): # noqa: B008
1218
"""
1319
These parameters are saved and used when nextNumber() is called.
1420

Diff for: quantum/ripple_adder_classic.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,16 @@ def full_adder(
5353
circuit.cx(input1_loc, input2_loc)
5454

5555

56+
# The default value for **backend** is the result of a function call which is not
57+
# normally recommended and causes flake8-bugbear to raise a B008 error. However,
58+
# in this case, this is accptable because `Aer.get_backend()` is called when the
59+
# function is defined and that same backend is then reused for all function calls.
60+
61+
5662
def ripple_adder(
57-
val1: int, val2: int, backend: BaseBackend = Aer.get_backend("qasm_simulator")
63+
val1: int,
64+
val2: int,
65+
backend: BaseBackend = Aer.get_backend("qasm_simulator"), # noqa: B008
5866
) -> int:
5967
"""
6068
Quantum Equivalent of a Ripple Adder Circuit
@@ -63,7 +71,7 @@ def ripple_adder(
6371
Currently only adds 'emulated' Classical Bits
6472
but nothing prevents us from doing this with hadamard'd bits :)
6573
66-
Only supports adding +ve Integers
74+
Only supports adding positive integers
6775
6876
>>> ripple_adder(3, 4)
6977
7
@@ -99,7 +107,7 @@ def ripple_adder(
99107
res = execute(circuit, backend, shots=1).result()
100108

101109
# The result is in binary. Convert it back to int
102-
return int(list(res.get_counts().keys())[0], 2)
110+
return int(list(res.get_counts())[0], 2)
103111

104112

105113
if __name__ == "__main__":

0 commit comments

Comments
 (0)