File fidelities.py
has 715 lines of code (exceeds 250 allowed). Consider refactoring. Open
"""Library of fidelity functions."""
import numpy as np
import tensorflow as tf
from typing import List, Dict
Function leakage_RB
has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring. Open
def leakage_RB(
propagators,
min_length: int = 5,
max_length: int = 500,
num_lengths: int = 20,
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Cyclomatic complexity is too high in function leakage_RB. (14) Open
@fid_reg_deco
def leakage_RB(
propagators,
min_length: int = 5,
max_length: int = 500,
- Read upRead up
- Exclude checks
Cyclomatic Complexity
Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.
Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:
Construct | Effect on CC | Reasoning |
---|---|---|
if | +1 | An if statement is a single decision. |
elif | +1 | The elif statement adds another decision. |
else | +0 | The else statement does not cause a new decision. The decision is at the if. |
for | +1 | There is a decision at the start of the loop. |
while | +1 | There is a decision at the while statement. |
except | +1 | Each except branch adds a new conditional path of execution. |
finally | +0 | The finally block is unconditionally executed. |
with | +1 | The with statement roughly corresponds to a try/except block (see PEP 343 for details). |
assert | +1 | The assert statement internally roughly equals a conditional statement. |
Comprehension | +1 | A list/set/dict comprehension of generator expression is equivalent to a for loop. |
Boolean Operator | +1 | Every boolean operator (and, or) adds a decision point. |
Function RB
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
def RB(
propagators,
min_length: int = 5,
max_length: int = 500,
num_lengths: int = 20,
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Cyclomatic complexity is too high in function RB. (9) Open
@fid_reg_deco
def RB(
propagators,
min_length: int = 5,
max_length: int = 500,
- Read upRead up
- Exclude checks
Cyclomatic Complexity
Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.
Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:
Construct | Effect on CC | Reasoning |
---|---|---|
if | +1 | An if statement is a single decision. |
elif | +1 | The elif statement adds another decision. |
else | +0 | The else statement does not cause a new decision. The decision is at the if. |
for | +1 | There is a decision at the start of the loop. |
while | +1 | There is a decision at the while statement. |
except | +1 | Each except branch adds a new conditional path of execution. |
finally | +0 | The finally block is unconditionally executed. |
with | +1 | The with statement roughly corresponds to a try/except block (see PEP 343 for details). |
assert | +1 | The assert statement internally roughly equals a conditional statement. |
Comprehension | +1 | A list/set/dict comprehension of generator expression is equivalent to a for loop. |
Boolean Operator | +1 | Every boolean operator (and, or) adds a decision point. |
Cyclomatic complexity is too high in function epc_analytical. (6) Open
@fid_reg_deco
def epc_analytical(propagators: dict, index, dims, proj: bool, cliffords=False):
# TODO check this work with new index and dims (double-check)
num_gates = len(dims)
if cliffords:
- Read upRead up
- Exclude checks
Cyclomatic Complexity
Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.
Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:
Construct | Effect on CC | Reasoning |
---|---|---|
if | +1 | An if statement is a single decision. |
elif | +1 | The elif statement adds another decision. |
else | +0 | The else statement does not cause a new decision. The decision is at the if. |
for | +1 | There is a decision at the start of the loop. |
while | +1 | There is a decision at the while statement. |
except | +1 | Each except branch adds a new conditional path of execution. |
finally | +0 | The finally block is unconditionally executed. |
with | +1 | The with statement roughly corresponds to a try/except block (see PEP 343 for details). |
assert | +1 | The assert statement internally roughly equals a conditional statement. |
Comprehension | +1 | A list/set/dict comprehension of generator expression is equivalent to a for loop. |
Boolean Operator | +1 | Every boolean operator (and, or) adds a decision point. |
Cyclomatic complexity is too high in function lindbladian_epc_analytical. (6) Open
@fid_reg_deco
def lindbladian_epc_analytical(
propagators: dict, index, dims, proj: bool, cliffords=False
):
num_gates = len(dims)
- Read upRead up
- Exclude checks
Cyclomatic Complexity
Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.
Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:
Construct | Effect on CC | Reasoning |
---|---|---|
if | +1 | An if statement is a single decision. |
elif | +1 | The elif statement adds another decision. |
else | +0 | The else statement does not cause a new decision. The decision is at the if. |
for | +1 | There is a decision at the start of the loop. |
while | +1 | There is a decision at the while statement. |
except | +1 | Each except branch adds a new conditional path of execution. |
finally | +0 | The finally block is unconditionally executed. |
with | +1 | The with statement roughly corresponds to a try/except block (see PEP 343 for details). |
assert | +1 | The assert statement internally roughly equals a conditional statement. |
Comprehension | +1 | A list/set/dict comprehension of generator expression is equivalent to a for loop. |
Boolean Operator | +1 | Every boolean operator (and, or) adds a decision point. |
Function RB
has 8 arguments (exceeds 4 allowed). Consider refactoring. Open
def RB(
Function state_transfer_infid_set
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
def state_transfer_infid_set(
Function orbit_infid
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
def orbit_infid(
Function leakage_RB
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
def leakage_RB(
Function lindbladian_epc_analytical
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def lindbladian_epc_analytical(
Function lindbladian_RB_left
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def lindbladian_RB_left(
Function state_transfer_from_states
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def state_transfer_from_states(states: tf.Tensor, index, dims, params, n_eval=-1):
Function unitary_infid_set
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def unitary_infid_set(propagators: dict, instructions: dict, index, dims, n_eval=-1):
Function average_infid_set
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def average_infid_set(
Function average_infid_seq
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def average_infid_seq(propagators: dict, instructions: dict, index, dims, n_eval=-1):
Function lindbladian_average_infid_set
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def lindbladian_average_infid_set(
Function lindbladian_RB_right
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def lindbladian_RB_right(propagators: dict, gate: str, index, dims, proj: bool):
Function state_transfer_infid
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def state_transfer_infid(ideal: np.ndarray, actual: tf.constant, index, dims, psi_0):
Function lindbladian_unitary_infid_set
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def lindbladian_unitary_infid_set(
Function epc_analytical
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def epc_analytical(propagators: dict, index, dims, proj: bool, cliffords=False):
Function orbit_infid
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def orbit_infid(
propagators,
RB_number: int = 30,
RB_length: int = 20,
lindbladian=False,
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Refactor this function to reduce its Cognitive Complexity from 19 to the 15 allowed. Open
def RB(
- Read upRead up
- Exclude checks
Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.
See
Function "RB" has 8 parameters, which is greater than the 7 authorized. Open
propagators,
min_length: int = 5,
max_length: int = 500,
num_lengths: int = 20,
num_seqs: int = 30,
- Read upRead up
- Exclude checks
A long parameter list can indicate that a new structure should be created to wrap the numerous parameters or that the function is doing too many things.
Noncompliant Code Example
With a maximum number of 4 parameters:
def do_something(param1, param2, param3, param4, param5): ...
Compliant Solution
def do_something(param1, param2, param3, param4): ...
Refactor this function to reduce its Cognitive Complexity from 33 to the 15 allowed. Open
def leakage_RB(
- Read upRead up
- Exclude checks
Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.
See
Remove this commented out code. Open
# if noise:
- Read upRead up
- Exclude checks
Programmers should not comment out code as it bloats programs and reduces readability.
Unused code should be deleted and can be retrieved from source control history if required.
See
- MISRA C:2004, 2.4 - Sections of code should not be "commented out".
- MISRA C++:2008, 2-7-2 - Sections of code shall not be "commented out" using C-style comments.
- MISRA C++:2008, 2-7-3 - Sections of code should not be "commented out" using C++ comments.
- MISRA C:2012, Dir. 4.4 - Sections of code should not be "commented out"
Remove this commented out code. Open
# if noise:
- Read upRead up
- Exclude checks
Programmers should not comment out code as it bloats programs and reduces readability.
Unused code should be deleted and can be retrieved from source control history if required.
See
- MISRA C:2004, 2.4 - Sections of code should not be "commented out".
- MISRA C++:2008, 2-7-2 - Sections of code shall not be "commented out" using C-style comments.
- MISRA C++:2008, 2-7-3 - Sections of code should not be "commented out" using C++ comments.
- MISRA C:2012, Dir. 4.4 - Sections of code should not be "commented out"
Rename function "leakage_RB" to match the regular expression ^[a-z_][a-z0-9_]{2,}$. Invalid
def leakage_RB(
- Read upRead up
- Exclude checks
Shared coding conventions allow teams to collaborate efficiently. This rule checks that all function names match a provided regular expression.
Noncompliant Code Example
With the default provided regular expression: ^[a-z_][a-z0-9_]{2,30}$
def MyFunction(a,b): ...
Compliant Solution
def my_function(a,b): ...
Rename function "lindbladian_RB_right" to match the regular expression ^[a-z_][a-z0-9_]{2,}$. Invalid
def lindbladian_RB_right(propagators: dict, gate: str, index, dims, proj: bool):
- Read upRead up
- Exclude checks
Shared coding conventions allow teams to collaborate efficiently. This rule checks that all function names match a provided regular expression.
Noncompliant Code Example
With the default provided regular expression: ^[a-z_][a-z0-9_]{2,30}$
def MyFunction(a,b): ...
Compliant Solution
def my_function(a,b): ...
Rename function "RB" to match the regular expression ^[a-z_][a-z0-9_]{2,}$. Invalid
def RB(
- Read upRead up
- Exclude checks
Shared coding conventions allow teams to collaborate efficiently. This rule checks that all function names match a provided regular expression.
Noncompliant Code Example
With the default provided regular expression: ^[a-z_][a-z0-9_]{2,30}$
def MyFunction(a,b): ...
Compliant Solution
def my_function(a,b): ...
Rename function "RB_fit" to match the regular expression ^[a-z_][a-z0-9_]{2,}$. Invalid
def RB_fit(len, r, A, B):
- Read upRead up
- Exclude checks
Shared coding conventions allow teams to collaborate efficiently. This rule checks that all function names match a provided regular expression.
Noncompliant Code Example
With the default provided regular expression: ^[a-z_][a-z0-9_]{2,30}$
def MyFunction(a,b): ...
Compliant Solution
def my_function(a,b): ...
Rename function "lindbladian_RB_left" to match the regular expression ^[a-z_][a-z0-9_]{2,}$. Invalid
def lindbladian_RB_left(
- Read upRead up
- Exclude checks
Shared coding conventions allow teams to collaborate efficiently. This rule checks that all function names match a provided regular expression.
Noncompliant Code Example
With the default provided regular expression: ^[a-z_][a-z0-9_]{2,30}$
def MyFunction(a,b): ...
Compliant Solution
def my_function(a,b): ...
Rename function "RB_leakage" to match the regular expression ^[a-z_][a-z0-9_]{2,}$. Invalid
def RB_leakage(len, r_leak, A_leak, B_leak):
- Read upRead up
- Exclude checks
Shared coding conventions allow teams to collaborate efficiently. This rule checks that all function names match a provided regular expression.
Noncompliant Code Example
With the default provided regular expression: ^[a-z_][a-z0-9_]{2,30}$
def MyFunction(a,b): ...
Compliant Solution
def my_function(a,b): ...
Rename function "RB_surv" to match the regular expression ^[a-z_][a-z0-9_]{2,}$. Invalid
def RB_surv(len, r, A, C):
- Read upRead up
- Exclude checks
Shared coding conventions allow teams to collaborate efficiently. This rule checks that all function names match a provided regular expression.
Noncompliant Code Example
With the default provided regular expression: ^[a-z_][a-z0-9_]{2,30}$
def MyFunction(a,b): ...
Compliant Solution
def my_function(a,b): ...