From d84a574918337dff2a8014e0d4829fddfcdb6740 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Mon, 30 Aug 2021 20:45:39 +0200 Subject: [PATCH 1/9] Approve functions used as default argumenets --- other/linear_congruential_generator.py | 2 +- quantum/ripple_adder_classic.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/other/linear_congruential_generator.py b/other/linear_congruential_generator.py index f8b604b8562d..3a48c0795075 100644 --- a/other/linear_congruential_generator.py +++ b/other/linear_congruential_generator.py @@ -8,7 +8,7 @@ class LinearCongruentialGenerator: A pseudorandom number generator. """ - def __init__(self, multiplier, increment, modulo, seed=int(time())): + def __init__(self, multiplier, increment, modulo, seed=int(time())): # noqa: B008 """ These parameters are saved and used when nextNumber() is called. diff --git a/quantum/ripple_adder_classic.py b/quantum/ripple_adder_classic.py index dc0c2103b2e5..310246f26159 100644 --- a/quantum/ripple_adder_classic.py +++ b/quantum/ripple_adder_classic.py @@ -54,7 +54,9 @@ def full_adder( def ripple_adder( - val1: int, val2: int, backend: BaseBackend = Aer.get_backend("qasm_simulator") + val1: int, + val2: int, + backend: BaseBackend = Aer.get_backend("qasm_simulator"), # noqa: B008 ) -> int: """ Quantum Equivalent of a Ripple Adder Circuit From fb3dd36564ed29c9230e1390042ca79fb3a1114c Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Tue, 31 Aug 2021 07:11:51 +0200 Subject: [PATCH 2/9] 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. --- other/linear_congruential_generator.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/other/linear_congruential_generator.py b/other/linear_congruential_generator.py index 3a48c0795075..da7d75415c70 100644 --- a/other/linear_congruential_generator.py +++ b/other/linear_congruential_generator.py @@ -14,6 +14,12 @@ def __init__(self, multiplier, increment, modulo, seed=int(time())): # noqa: B0 modulo is the largest number that can be generated (exclusive). The most efficient values are powers of 2. 2^32 is a common value. + + 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. """ self.multiplier = multiplier self.increment = increment From ba687e9ccd20da2b3094152e0fdade760d81d8bc Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Tue, 31 Aug 2021 07:23:57 +0200 Subject: [PATCH 3/9] 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. --- quantum/ripple_adder_classic.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/quantum/ripple_adder_classic.py b/quantum/ripple_adder_classic.py index 310246f26159..561156c37c87 100644 --- a/quantum/ripple_adder_classic.py +++ b/quantum/ripple_adder_classic.py @@ -65,7 +65,12 @@ def ripple_adder( Currently only adds 'emulated' Classical Bits but nothing prevents us from doing this with hadamard'd bits :) - Only supports adding +ve Integers + Only supports adding positive integers + + 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. >>> ripple_adder(3, 4) 7 @@ -101,7 +106,7 @@ def ripple_adder( res = execute(circuit, backend, shots=1).result() # The result is in binary. Convert it back to int - return int(list(res.get_counts().keys())[0], 2) + return int(list(res.get_counts())[0], 2) if __name__ == "__main__": From 43b8db3d36e134bdae57f41ae40275b7da06bc70 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Tue, 31 Aug 2021 07:45:40 +0200 Subject: [PATCH 4/9] Update linear_congruential_generator.py --- other/linear_congruential_generator.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/other/linear_congruential_generator.py b/other/linear_congruential_generator.py index da7d75415c70..777ee6355b9b 100644 --- a/other/linear_congruential_generator.py +++ b/other/linear_congruential_generator.py @@ -8,18 +8,18 @@ class LinearCongruentialGenerator: A pseudorandom number generator. """ + # 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. + def __init__(self, multiplier, increment, modulo, seed=int(time())): # noqa: B008 """ These parameters are saved and used when nextNumber() is called. modulo is the largest number that can be generated (exclusive). The most efficient values are powers of 2. 2^32 is a common value. - - 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. """ self.multiplier = multiplier self.increment = increment From deb4a351473fa10afdd1c7fe1d0ef2d2231e604a Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Tue, 31 Aug 2021 07:47:44 +0200 Subject: [PATCH 5/9] Update ripple_adder_classic.py --- quantum/ripple_adder_classic.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/quantum/ripple_adder_classic.py b/quantum/ripple_adder_classic.py index 561156c37c87..91130bda0671 100644 --- a/quantum/ripple_adder_classic.py +++ b/quantum/ripple_adder_classic.py @@ -53,6 +53,11 @@ def full_adder( circuit.cx(input1_loc, input2_loc) +# 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. + def ripple_adder( val1: int, val2: int, @@ -66,11 +71,6 @@ def ripple_adder( but nothing prevents us from doing this with hadamard'd bits :) Only supports adding positive integers - - 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. >>> ripple_adder(3, 4) 7 From af3900a8c81f05328a3efca916dfc81a1642cdd3 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Tue, 31 Aug 2021 07:49:38 +0200 Subject: [PATCH 6/9] Update ripple_adder_classic.py --- quantum/ripple_adder_classic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quantum/ripple_adder_classic.py b/quantum/ripple_adder_classic.py index 91130bda0671..3a559f063c6c 100644 --- a/quantum/ripple_adder_classic.py +++ b/quantum/ripple_adder_classic.py @@ -52,12 +52,12 @@ def full_adder( circuit.cx(input2_loc, carry_in) circuit.cx(input1_loc, input2_loc) - # 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. + def ripple_adder( val1: int, val2: int, From 3a5276f025023db8603ac2ded082a8f259d27d16 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Tue, 31 Aug 2021 07:50:52 +0200 Subject: [PATCH 7/9] Update ripple_adder_classic.py --- quantum/ripple_adder_classic.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/quantum/ripple_adder_classic.py b/quantum/ripple_adder_classic.py index 3a559f063c6c..48f96a5dd557 100644 --- a/quantum/ripple_adder_classic.py +++ b/quantum/ripple_adder_classic.py @@ -54,8 +54,8 @@ def full_adder( # 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. +# in this case, this is accptable because `Aer.get_backend()` is called when the +# function is defined and that same backend is then reused for function calls. def ripple_adder( From fa71c3ae91fa5b4599d1f648221a9b0942ff1dd4 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Tue, 31 Aug 2021 07:51:23 +0200 Subject: [PATCH 8/9] Update ripple_adder_classic.py --- quantum/ripple_adder_classic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quantum/ripple_adder_classic.py b/quantum/ripple_adder_classic.py index 48f96a5dd557..861b40941d41 100644 --- a/quantum/ripple_adder_classic.py +++ b/quantum/ripple_adder_classic.py @@ -55,7 +55,7 @@ def full_adder( # 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, this is accptable because `Aer.get_backend()` is called when the -# function is defined and that same backend is then reused for function calls. +# function is defined and that same backend is then reused for all function calls. def ripple_adder( From c27dc9aadb803ffe236ded472fa3f4e024ea61ff Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Tue, 31 Aug 2021 07:53:17 +0200 Subject: [PATCH 9/9] Update ripple_adder_classic.py --- quantum/ripple_adder_classic.py | 1 + 1 file changed, 1 insertion(+) diff --git a/quantum/ripple_adder_classic.py b/quantum/ripple_adder_classic.py index 861b40941d41..8539a62afd52 100644 --- a/quantum/ripple_adder_classic.py +++ b/quantum/ripple_adder_classic.py @@ -52,6 +52,7 @@ def full_adder( circuit.cx(input2_loc, carry_in) circuit.cx(input1_loc, input2_loc) + # 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, this is accptable because `Aer.get_backend()` is called when the