qutip/qutip-qip

View on GitHub
src/qutip_qip/compiler/scheduler.py

Summary

Maintainability
A
1 hr
Test Coverage

Function schedule has a Cognitive Complexity of 26 (exceeds 20 allowed). Consider refactoring.
Open

    def schedule(
        self,
        circuit,
        gates_schedule=False,
        return_cycles_list=False,
Severity: Minor
Found in src/qutip_qip/compiler/scheduler.py - About 1 hr to fix

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

Avoid too many return statements within this function.
Wontfix

        return instruction_start_time
Severity: Major
Found in src/qutip_qip/compiler/scheduler.py - About 30 mins to fix

    Function generate_dependency_graph has a Cognitive Complexity of 21 (exceeds 20 allowed). Consider refactoring.
    Open

        def generate_dependency_graph(self, commuting):
            """
            Generate the instruction dependency graph.
            It modifies the class attribute `nodes`, where each element (node)
            is an `Instruction`.
    Severity: Minor
    Found in src/qutip_qip/compiler/scheduler.py - About 25 mins to fix

    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

    Do not assign a lambda expression, use a def
    Wontfix

                commutation_rules = lambda *args, **kwargs: False
    Severity: Minor
    Found in src/qutip_qip/compiler/scheduler.py by pep8

    Compound statements (on the same line) are generally discouraged.

    While sometimes it's okay to put an if/for/while with a small body
    on the same line, never do this for multi-clause statements.
    Also avoid folding such long lines!
    
    Always use a def statement instead of an assignment statement that
    binds a lambda expression directly to a name.
    
    Okay: if foo == 'blah':\n    do_blah_thing()
    Okay: do_one()
    Okay: do_two()
    Okay: do_three()
    
    E701: if foo == 'blah': do_blah_thing()
    E701: for x in lst: total += x
    E701: while t < 10: t = delay()
    E701: if foo == 'blah': do_blah_thing()
    E701: else: do_non_blah_thing()
    E701: try: something()
    E701: finally: cleanup()
    E701: if foo == 'blah': one(); two(); three()
    E702: do_one(); do_two(); do_three()
    E703: do_four();  # useless semicolon
    E704: def f(x): return 2*x
    E731: f = lambda x: 2*x

    There are no issues that match your filters.

    Category
    Status