q-optimize/c3

View on GitHub

Showing 303 of 330 total issues

Function start_log has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def start_log(self, opt, logdir):
        self.opt_map = opt.pmap.get_opt_map()
        print("create log at", logdir)
        self.writer = tf.summary.create_file_writer(
            logdir=logdir,
Severity: Minor
Found in c3/optimizers/optimizer.py - About 35 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

Avoid too many return statements within this function.
Open

            return (
Severity: Major
Found in c3/libraries/chip.py - About 30 mins to fix

    Avoid too many return statements within this function.
    Open

                return val * (10 ** (-3 * (len(big_units) - 1))), big_units[-1]
    Severity: Major
    Found in c3/utils/utils.py - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

                  return tape.gradient(val, phi_variable)
      Severity: Major
      Found in c3/libraries/chip.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                    return grad
        Severity: Major
        Found in c3/libraries/chip.py - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

              return sign * (10 ** (tmp % 3)), prefix
          Severity: Major
          Found in c3/utils/utils.py - About 30 mins to fix

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

            @hamiltonian_reg_deco
            def resonator(a):
                """
                Harmonic oscillator hamiltonian given the annihilation operator.
            
            
            Severity: Minor
            Found in c3/libraries/hamiltonians.py and 1 other location - About 30 mins to fix
            c3/libraries/hamiltonians.py on lines 165..182

            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 32.

            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

                t = tf.reshape(tf.cast(t, tf.float64), [1, t.shape[0]])
            Severity: Minor
            Found in c3/libraries/envelopes.py and 1 other location - About 30 mins to fix
            c3/libraries/envelopes.py on lines 190..190

            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 32.

            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

                t = tf.reshape(tf.cast(t, tf.float64), [1, t.shape[0]])
            Severity: Minor
            Found in c3/libraries/envelopes.py and 1 other location - About 30 mins to fix
            c3/libraries/envelopes.py on lines 167..167

            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 32.

            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

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

            @hamiltonian_reg_deco
            def z_drive(a):
                """
                Semiclassical drive.
            
            
            Severity: Minor
            Found in c3/libraries/hamiltonians.py and 1 other location - About 30 mins to fix
            c3/libraries/hamiltonians.py on lines 16..33

            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 32.

            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

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

            def slepian_fourier(t, params):
                """
                ----
                """
                t_final = tf.cast(params["t_final"].get_value(), tf.float64)
            Severity: Minor
            Found in c3/libraries/envelopes.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 quick_setup has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def quick_setup(self, cfg, base_dir: str = None) -> None:
                    """
                    Load a quick setup cfg and create all necessary components.
            
                    Parameters
            Severity: Minor
            Found in c3/experiment.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):
                    phi = (
                        (self.params["phi"].get_value() + phi_sig)
                        / self.params["phi_0"].get_value()
                        * 2
            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 Hs_of_t has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def Hs_of_t(self, signal, interpolate_res=2):
                    """
                    Generate a list of Hamiltonians for each time step of interpolated signal for Runge-Kutta Methods.
            
                    Args:
            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_noise has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def get_noise(self, sig):
                    noise_amp = self.params["noise_amp"].get_value().numpy()
                    bfl_num = int(self.params["bfl_num"].get_value().numpy())
                    noise = []
                    bfls = 2 * np.random.randint(2, size=bfl_num) - 1
            Severity: Minor
            Found in c3/generator/devices.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 set_max_excitations has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def set_max_excitations(self, max_excitations) -> None:
                    """
                    Set the maximum number of excitations in the system used for propagation.
                    """
                    if max_excitations:
            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 __initialize_parameters has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def __initialize_parameters(self) -> None:
                    par_lens = {}
                    pars = {}
                    par_ids_model = []
                    for comp in self.__components.values():
            Severity: Minor
            Found in c3/parametermap.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 set_init_state has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def set_init_state(self, state):
                    if self.lindbladian and state.shape[0] != state.shape[1]:
                        if state.shape[0] == self.tot_dim:
                            self.init_state = tf_utils.tf_state_to_dm(state)
                        elif state.shape[0] == self.tot_dim**2:
            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 ask_yn has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

            def ask_yn() -> bool:
                """Ask for y/n user decision in the command line."""
                asking = True
                text = input("(y/n): ")
                if text == "y":
            Severity: Minor
            Found in c3/utils/utils.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 fromdict has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def fromdict(self, cfg: dict) -> None:
                    """
                    Load a file and parse it to create a Model object.
            
                    Parameters
            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

            Severity
            Category
            Status
            Source
            Language