q-optimize/c3

View on GitHub

Showing 303 of 330 total issues

File modellearning.py has 385 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""Object that deals with the model learning."""

import os
import time
import pickle
Severity: Minor
Found in c3/optimizers/modellearning.py - About 5 hrs to fix

    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,
    Severity: Minor
    Found in c3/libraries/fidelities.py - About 4 hrs 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

    Function process has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
    Open

        def process(
            self, instr: Instruction, chan: str, signal: List[Dict[str, Any]]
        ) -> dict:
            # TODO check somewhere that there is only 1 carrier per instruction
            ts = self.create_ts(instr.t_start, instr.t_end, centered=True)
    Severity: Minor
    Found in c3/generator/devices.py - About 4 hrs 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

    Cyclomatic complexity is too high in function run_cfg. (23)
    Open

    def run_cfg(cfg, opt_config_filename, debug=False):
        """Execute an optimization problem described in the cfg file.
    
        Parameters
        ----------
    Severity: Minor
    Found in c3/main.py by radon

    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.

    Source: http://radon.readthedocs.org/en/latest/intro.html

    File optimizer.py has 361 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    """Optimizer object, where the optimal control is done."""
    
    import os
    import time
    from typing import Callable, Union, List, Dict, Optional, Any
    Severity: Minor
    Found in c3/optimizers/optimizer.py - About 4 hrs to fix

      Identical blocks of code found in 2 locations. Consider refactoring.
      Open

          gauss_der = (
              tf.exp(-((t - t_final / 2) ** 2) / (2 * sigma**2))
              * (t - t_final / 2)
              / sigma**2
      Severity: Major
      Found in c3/libraries/envelopes.py and 1 other location - About 4 hrs to fix
      c3/libraries/envelopes.py on lines 495..498

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 81.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Identical blocks of code found in 2 locations. Consider refactoring.
      Open

          gauss_der = (
              tf.exp(-((t - t_final / 2) ** 2) / (2 * sigma**2))
              * (t - t_final / 2)
              / sigma**2
      Severity: Major
      Found in c3/libraries/envelopes.py and 1 other location - About 4 hrs to fix
      c3/libraries/envelopes.py on lines 508..511

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 81.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Cyclomatic complexity is too high in function cmaes. (21)
      Open

      @algo_reg_deco
      def cmaes(x_init, fun=None, fun_grad=None, grad_lookup=None, options={}):
          """
          Wrapper for the pycma implementation of CMA-Es. See also:
      
      
      Severity: Minor
      Found in c3/libraries/algorithms.py by radon

      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.

      Source: http://radon.readthedocs.org/en/latest/intro.html

      Quantity has 33 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class Quantity:
          """
          Represents any physical quantity used in the model or the pulse
          specification. For arithmetic operations just the numeric value is used. The
          value itself is stored in an optimizer friendly way as a float between -1
      Severity: Minor
      Found in c3/c3objs.py - About 4 hrs to fix

        Identical blocks of code found in 2 locations. Consider refactoring.
        Open

            shape = (
                (1 + tf.math.erf((t - t_up) / risefall))
                / 2
                * (1 + tf.math.erf((-t + t_down) / risefall))
                / 2
        Severity: Major
        Found in c3/libraries/envelopes.py and 1 other location - About 4 hrs to fix
        c3/libraries/envelopes.py on lines 245..249

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 75.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Identical blocks of code found in 2 locations. Consider refactoring.
        Open

            return (
                (1 + tf.math.erf((t - t_up) / risefall))
                / 2
                * (1 + tf.math.erf((-t + t_down) / risefall))
                / 2
        Severity: Major
        Found in c3/libraries/envelopes.py and 1 other location - About 4 hrs to fix
        c3/libraries/envelopes.py on lines 272..276

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 75.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        File c3objs.py has 332 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        """Basic custom objects."""
        
        import hjson
        from typing import List
        import numpy as np
        Severity: Minor
        Found in c3/c3objs.py - About 4 hrs to fix

          File gates.py has 331 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          import hjson
          import numpy as np
          import tensorflow as tf
          from c3.c3objs import C3obj, Quantity, hjson_encode
          from c3.signal.pulse import Envelope, Carrier
          Severity: Minor
          Found in c3/signal/gates.py - About 3 hrs to fix

            Identical blocks of code found in 2 locations. Consider refactoring.
            Open

                q1 = chip.Qubit(
                    name="Q1",
                    desc="Qubit 1",
                    freq=Qty(
                        value=freq,
            Severity: Major
            Found in examples/single_qubit_blackbox_exp.py and 1 other location - About 3 hrs to fix
            examples/single_qubit_experiment.py on lines 30..46

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 73.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Identical blocks of code found in 2 locations. Consider refactoring.
            Open

                q1 = chip.Qubit(
                    name="Q1",
                    desc="Qubit 1",
                    freq=Qty(
                        value=freq,
            Severity: Major
            Found in examples/single_qubit_experiment.py and 1 other location - About 3 hrs to fix
            examples/single_qubit_blackbox_exp.py on lines 32..48

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 73.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Cyclomatic complexity is too high in function jsonify_list. (18)
            Open

            def jsonify_list(data, transform_arrays=True):
                # try:
                if data is None:
                    return
                if isinstance(data, dict):
            Severity: Minor
            Found in c3/c3objs.py by radon

            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.

            Source: http://radon.readthedocs.org/en/latest/intro.html

            Function gcmaes has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
            Open

            def gcmaes(x_init, fun=None, fun_grad=None, grad_lookup=None, options={}):
                """
                EXPERIMENTAL CMA-Es where every point in the cloud is optimized with LBFG-S and the
                resulting cloud and results are used for the CMA update.
                """
            Severity: Minor
            Found in c3/libraries/algorithms.py - About 3 hrs 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

            Cyclomatic complexity is too high in method process. (16)
            Open

                def process(
                    self, instr: Instruction, chan: str, signal: List[Dict[str, Any]]
                ) -> dict:
                    # TODO check somewhere that there is only 1 carrier per instruction
                    ts = self.create_ts(instr.t_start, instr.t_end, centered=True)
            Severity: Minor
            Found in c3/generator/devices.py by radon

            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.

            Source: http://radon.readthedocs.org/en/latest/intro.html

            Function process has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
            Open

                def process(self, populations, labels=None):
                    """
                    Apply a readout procedure to a population vector. Very specialized
                    at the moment.
            
            
            Severity: Minor
            Found in c3/experiment.py - About 3 hrs 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

            Cyclomatic complexity is too high in function gcmaes. (15)
            Open

            @algo_reg_deco
            def gcmaes(x_init, fun=None, fun_grad=None, grad_lookup=None, options={}):
                """
                EXPERIMENTAL CMA-Es where every point in the cloud is optimized with LBFG-S and the
                resulting cloud and results are used for the CMA update.
            Severity: Minor
            Found in c3/libraries/algorithms.py by radon

            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.

            Source: http://radon.readthedocs.org/en/latest/intro.html

            Severity
            Category
            Status
            Source
            Language