qutip/qutip-qip

View on GitHub

Showing 151 of 164 total issues

Avoid deeply nested control flow statements.
Open

                    if start + end - i - i == 1 and (end - start + 1) % 2 == 0:
                        # Apply required gate if control and target are
                        # adjacent to each other, provided |control-target|
                        # is even.
                        if end == gate.controls[0]:
Severity: Major
Found in src/qutip_qip/transpiler/chain.py - About 45 mins to fix

    Avoid deeply nested control flow statements.
    Open

                            if len(gate.targets) > 1:
                                if gate.name == "SWAP":
                                    if _swap_processing:
                                        col.append(r" \qswap \qw")
                                        continue
    Severity: Major
    Found in src/qutip_qip/circuit/circuit.py - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                          if (
                              N + start - end - i - i == 1
                              and (N - end + start + 1) % 2 == 0
                          ):
                              temp.add_gate(gate.name, [i, i + 1])
      Severity: Major
      Found in src/qutip_qip/transpiler/chain.py - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                                if end == gate.controls[0]:
                                    temp.gates.append(
                                        Gate(gate.name, targets=[i], controls=[i + 1])
                                    )
                                else:
        Severity: Major
        Found in src/qutip_qip/circuit/circuit.py - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                                  if end == gate.controls[0]:
                                      temp.gates.append(
                                          Gate(
                                              gate.name,
                                              targets=[i + 1],
          Severity: Major
          Found in src/qutip_qip/circuit/circuit.py - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                if (
                                    N + start - end - i - i == 1
                                    and (N - end + start + 1) % 2 == 0
                                ):
                                    if end == gate.controls[0]:
            Severity: Major
            Found in src/qutip_qip/transpiler/chain.py - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                  if start + end - i - i == 1 and (end - start + 1) % 2 == 0:
                                      qc_t.add_gate(gate.name, [i, i + 1])
                                  elif (start + end - i - i) == 2 and (
                                      end - start + 1
                                  ) % 2 == 1:
              Severity: Major
              Found in src/qutip_qip/transpiler/chain.py - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                    if j < N - end - 2:
                                        if gate.name in ["CNOT", "CSIGN"]:
                                            qc_t.add_gate(
                                                gate.name,
                                                end + gate.targets[0],
                Severity: Major
                Found in src/qutip_qip/transpiler/chain.py - About 45 mins to fix

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

                                      if (
                                          N + start - end - i - i == 1
                                          and (N - end + start + 1) % 2 == 0
                  Severity: Major
                  Found in src/qutip_qip/transpiler/chain.py and 3 other locations - About 40 mins to fix
                  src/qutip_qip/transpiler/chain.py on lines 117..119
                  src/qutip_qip/transpiler/chain.py on lines 219..221
                  src/qutip_qip/transpiler/chain.py on lines 225..227

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

                  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 4 locations. Consider refactoring.
                  Open

                                      if (
                                          N + start - end - i - i == 1
                                          and (N - end + start + 1) % 2 == 0
                  Severity: Major
                  Found in src/qutip_qip/transpiler/chain.py and 3 other locations - About 40 mins to fix
                  src/qutip_qip/transpiler/chain.py on lines 104..106
                  src/qutip_qip/transpiler/chain.py on lines 117..119
                  src/qutip_qip/transpiler/chain.py on lines 225..227

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

                  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 _get_qobjevo_helper has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring.
                  Open

                      def _get_qobjevo_helper(self, spline_kind, dims):
                          """
                          Please refer to `_Evoelement.get_qobjevo` for documentation.
                          """
                          mat = self.get_qobj(dims)
                  Severity: Minor
                  Found in src/qutip_qip/pulse.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

                  Function _concatenate_pulses has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring.
                  Open

                      def _concatenate_pulses(
                          self, pulse_instructions, scheduled_start_time, num_controls
                      ):
                          """
                          Concatenate compiled pulses coefficients and tlist for each pulse.
                  Severity: Minor
                  Found in src/qutip_qip/compiler/gatecompiler.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

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

                      def _is_pulses_valid(self):
                          """
                          Check if the pulses are in the correct shape.
                  
                          Returns: bool
                  Severity: Minor
                  Found in src/qutip_qip/device/processor.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 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

                  Missing whitespace around operator
                  Open

                              if not isinstance(pulse, Drift) and pulse.label=="systematic_noise":
                  Severity: Minor
                  Found in tests/test_noise.py by pep8

                  Surround operators with a single space on either side.

                  - Always surround these binary operators with a single space on
                    either side: assignment (=), augmented assignment (+=, -= etc.),
                    comparisons (==, <, >, !=, <=, >=, in, not in, is, is not),
                    Booleans (and, or, not).
                  
                  - If operators with different priorities are used, consider adding
                    whitespace around the operators with the lowest priorities.
                  
                  Okay: i = i + 1
                  Okay: submitted += 1
                  Okay: x = x * 2 - 1
                  Okay: hypot2 = x * x + y * y
                  Okay: c = (a + b) * (a - b)
                  Okay: foo(bar, key='word', *args, **kwargs)
                  Okay: alpha[:-i]
                  
                  E225: i=i+1
                  E225: submitted +=1
                  E225: x = x /2 - 1
                  E225: z = x **y
                  E225: z = 1and 1
                  E226: c = (a+b) * (a-b)
                  E226: hypot2 = x*x + y*y
                  E227: c = a|b
                  E228: msg = fmt%(errno, errmsg)

                  Module level import not at top of file
                  Open

                  from qiskit_aer import AerSimulator
                  Severity: Minor
                  Found in tests/test_qiskit.py by pep8

                  Place imports at the top of the file.

                  Always put imports at the top of the file, just after any module
                  comments and docstrings, and before module globals and constants.
                  
                  Okay: import os
                  Okay: # this is a comment\nimport os
                  Okay: '''this is a module docstring'''\nimport os
                  Okay: r'''this is a module docstring'''\nimport os
                  Okay:
                  try:\n\timport x\nexcept ImportError:\n\tpass\nelse:\n\tpass\nimport y
                  Okay:
                  try:\n\timport x\nexcept ImportError:\n\tpass\nfinally:\n\tpass\nimport y
                  E402: a=1\nimport os
                  E402: 'One string'\n"Two string"\nimport os
                  E402: a=1\nfrom sys import x
                  
                  Okay: if x:\n    import os

                  Unexpected spaces around keyword / parameter equals
                  Open

                      pytest.param("step_func", id = "discrete"),
                  Severity: Minor
                  Found in tests/test_compiler.py by pep8

                  Don't use spaces around the '=' sign in function arguments.

                  Don't use spaces around the '=' sign when used to indicate a
                  keyword argument or a default parameter value, except when
                  using a type annotation.
                  
                  Okay: def complex(real, imag=0.0):
                  Okay: return magic(r=real, i=imag)
                  Okay: boolean(a == b)
                  Okay: boolean(a != b)
                  Okay: boolean(a <= b)
                  Okay: boolean(a >= b)
                  Okay: def foo(arg: int = 42):
                  Okay: async def foo(arg: int = 42):
                  
                  E251: def complex(real, imag = 0.0):
                  E251: return magic(r = real, i = imag)
                  E252: def complex(real, image: float=0.0):

                  Missing whitespace around operator
                  Open

                      tlist = abs(gate.arg_value) / (2 * g) / np.pi/ 2
                  Severity: Minor
                  Found in tests/test_compiler.py by pep8

                  Surround operators with a single space on either side.

                  - Always surround these binary operators with a single space on
                    either side: assignment (=), augmented assignment (+=, -= etc.),
                    comparisons (==, <, >, !=, <=, >=, in, not in, is, is not),
                    Booleans (and, or, not).
                  
                  - If operators with different priorities are used, consider adding
                    whitespace around the operators with the lowest priorities.
                  
                  Okay: i = i + 1
                  Okay: submitted += 1
                  Okay: x = x * 2 - 1
                  Okay: hypot2 = x * x + y * y
                  Okay: c = (a + b) * (a - b)
                  Okay: foo(bar, key='word', *args, **kwargs)
                  Okay: alpha[:-i]
                  
                  E225: i=i+1
                  E225: submitted +=1
                  E225: x = x /2 - 1
                  E225: z = x **y
                  E225: z = 1and 1
                  E226: c = (a+b) * (a-b)
                  E226: hypot2 = x*x + y*y
                  E227: c = a|b
                  E228: msg = fmt%(errno, errmsg)

                  Unexpected spaces around keyword / parameter equals
                  Open

                      pytest.param(SCQubits, {}, id = "SCQubits"),
                  Severity: Minor
                  Found in tests/test_device.py by pep8

                  Don't use spaces around the '=' sign in function arguments.

                  Don't use spaces around the '=' sign when used to indicate a
                  keyword argument or a default parameter value, except when
                  using a type annotation.
                  
                  Okay: def complex(real, imag=0.0):
                  Okay: return magic(r=real, i=imag)
                  Okay: boolean(a == b)
                  Okay: boolean(a != b)
                  Okay: boolean(a <= b)
                  Okay: boolean(a >= b)
                  Okay: def foo(arg: int = 42):
                  Okay: async def foo(arg: int = 42):
                  
                  E251: def complex(real, imag = 0.0):
                  E251: return magic(r = real, i = imag)
                  E252: def complex(real, image: float=0.0):

                  Unexpected spaces around keyword / parameter equals
                  Open

                      pytest.param(SCQubits, {}, id = "SCQubits"),
                  Severity: Minor
                  Found in tests/test_device.py by pep8

                  Don't use spaces around the '=' sign in function arguments.

                  Don't use spaces around the '=' sign when used to indicate a
                  keyword argument or a default parameter value, except when
                  using a type annotation.
                  
                  Okay: def complex(real, imag=0.0):
                  Okay: return magic(r=real, i=imag)
                  Okay: boolean(a == b)
                  Okay: boolean(a != b)
                  Okay: boolean(a <= b)
                  Okay: boolean(a >= b)
                  Okay: def foo(arg: int = 42):
                  Okay: async def foo(arg: int = 42):
                  
                  E251: def complex(real, imag = 0.0):
                  E251: return magic(r = real, i = imag)
                  E252: def complex(real, image: float=0.0):
                  Severity
                  Category
                  Status
                  Source
                  Language