q-optimize/c3

View on GitHub

Showing 303 of 330 total issues

Function get_minimum_phi_var has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    def get_minimum_phi_var(self, init_phi_variable: tf.float64 = 0, phi_sig=0):
        # TODO maybe improve to analytical funciton here
        # TODO do not reevaluate if not necessary
        phi_0 = self.params["phi_0"].get_value()
        initial_pot_eval = self.get_potential_function(0.0, 0)
Severity: Minor
Found in c3/libraries/chip.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

Function update_Hamiltonians has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    def update_Hamiltonians(self):
        """Recompute the matrix representations of the Hamiltonians."""
        control_hams = dict()
        hamiltonians = dict()
        for key, sub in self.subsystems.items():
Severity: Minor
Found in c3/model.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

Function get_Frame_Rotation has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    def get_Frame_Rotation(self, t_final: np.float64, freqs: dict, framechanges: dict):
        """
        Compute the frame rotation needed to align Lab frame and rotating Eigenframes
        of the qubits.

Severity: Minor
Found in c3/model.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

Function get_potential_function has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    def get_potential_function(
        self, phi_variable, deriv_order=1, phi_sig=0
    ) -> tf.float64:
        if phi_sig != 0:
            raise NotImplementedError()
Severity: Minor
Found in c3/libraries/chip.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

Consider possible security implications associated with pickle module.
Open

import pickle
Severity: Info
Found in c3/optimizers/modellearning.py by bandit

Remove this commented out code.
Open

        # return self.slice_num
Severity: Major
Found in c3/generator/devices.py by sonar-python

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"

Consider possible security implications associated with pickle module.
Open

import pickle
Severity: Info
Found in c3/experiment.py by bandit

Refactor this function to reduce its Cognitive Complexity from 34 to the 15 allowed.
Open

    def process(
Severity: Critical
Found in c3/generator/devices.py by sonar-python

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

Consider possible security implications associated with pickle module.
Open

import pickle
Severity: Info
Found in c3/optimizers/calibration.py by bandit

Remove this commented out code.
Open

        # ts = tf.range(t_start, t_end + 1e-16, dt)
Severity: Major
Found in c3/generator/devices.py by sonar-python

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

        # phi_0 = self.params["phi_0"].get_value()
Severity: Major
Found in c3/generator/devices.py by sonar-python

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"

Refactor this function to reduce its Cognitive Complexity from 25 to the 15 allowed.
Open

def run_cfg(cfg, opt_config_filename, debug=False):
Severity: Critical
Found in c3/main.py by sonar-python

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

        # fc = 1e7 / self.resolution
Severity: Major
Found in c3/generator/devices.py by sonar-python

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"

Pickle and modules that wrap it can be unsafe when used to deserialize untrusted data, possible security issue.
Open

                self.learn_data[target] = pickle.load(file)
Severity: Minor
Found in c3/optimizers/modellearning.py by bandit

The input method in Python 2 will read from standard input, evaluate and run the resulting string as python source code. This is similar, though in many ways worse, then using eval. On Python 2, use raw_input instead, input is safe in Python 3.
Open

        text = input("Please write y or n and press enter: ")
Severity: Major
Found in c3/utils/utils.py by bandit

Refactor this function to reduce its Cognitive Complexity from 26 to the 15 allowed.
Open

def gcmaes(x_init, fun=None, fun_grad=None, grad_lookup=None, options={}):
Severity: Critical
Found in c3/libraries/algorithms.py by sonar-python

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

Merge this if statement with the enclosing one.
Open

            if es.sigma < stop_sigma:
Severity: Major
Found in c3/libraries/algorithms.py by sonar-python

Merging collapsible if statements increases the code's readability.

Noncompliant Code Example

if condition1:
    if condition2:
        # ...

Compliant Solution

if condition1 and condition2:
    # ...

Pickle and modules that wrap it can be unsafe when used to deserialize untrusted data, possible security issue.
Open

                    measurements.append(pickle.load(pickle_file))
Severity: Minor
Found in c3/optimizers/calibration.py by bandit

The input method in Python 2 will read from standard input, evaluate and run the resulting string as python source code. This is similar, though in many ways worse, then using eval. On Python 2, use raw_input instead, input is safe in Python 3.
Open

    text = input("(y/n): ")
Severity: Major
Found in c3/utils/utils.py by bandit

Merge this if statement with the enclosing one.
Open

            if "adjust_exp" in cfg:
Severity: Major
Found in c3/main.py by sonar-python

Merging collapsible if statements increases the code's readability.

Noncompliant Code Example

if condition1:
    if condition2:
        # ...

Compliant Solution

if condition1 and condition2:
    # ...
Severity
Category
Status
Source
Language