mfinzi/pristine-ml

View on GitHub

Showing 97 of 97 total issues

Function split_dataset has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

def split_dataset(dataset,splits):
    """ Inputs: A torchvision.dataset DATASET and a dictionary SPLITS
        containing fractions or number of elements for each of the new datasets.
        Allows values (0,1] or (1,N] or -1 to fill with remaining.
        Example {'train':-1,'val':.1} will create a (.9, .1) split of the dataset.
Severity: Minor
Found in oil/datasetup/datasets.py - About 2 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 unflatten has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

def unflatten(d,sep='/'):
    """Take a dictionary with keys {'k1/k2/k3':v} to {'k1':{'k2':{'k3':v}}}
        as outputted by flatten """
    out_dict={}
    for k,v in d.items():
Severity: Minor
Found in oil/tuning/configGenerator.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

Function makeTrainer has 15 arguments (exceeds 4 allowed). Consider refactoring.
Open

def makeTrainer(*,dataset=CIFAR10,network=layer13,num_epochs=100,
Severity: Major
Found in oil/recipes/simpleTrial.py - About 1 hr to fix

    Function __init__ has 13 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1,bias=True, eps=1e-2, n_iter=5, momentum=0.1, mode=4, num_groups=16,debug=False):
    Severity: Major
    Found in oil/architectures/parts/deconv.py - About 1 hr to fix

      Function makeTrainer has 13 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      def makeTrainer(*,dataset=CIFAR10,network=layer13,num_epochs=200,
      Severity: Major
      Found in oil/recipes/trainPi.py - About 1 hr to fix

        Function makeTrainer has 12 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        def makeTrainer(*,gen=resnetgan.Generator,disc=resnetgan.Discriminator,
        Severity: Major
        Found in oil/recipes/trainGan.py - About 1 hr to fix

          Function __init__ has 12 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1,bias=True, eps=1e-2, n_iter=5, momentum=0.1, num_groups=16,sampling_stride=3):
          Severity: Major
          Found in oil/architectures/parts/deconv.py - About 1 hr to fix

            Function makeTrainer has 12 arguments (exceeds 4 allowed). Consider refactoring.
            Open

            def makeTrainer(*,gen=cgan.Generator,disc=cgan.Discriminator,
            Severity: Major
            Found in oil/recipes/trainCGan.py - About 1 hr to fix

              Function _find_images_and_annotation has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
              Open

              def _find_images_and_annotation(root_dir):
                  images = {}
                  attr = None
                  assert os.path.exists(root_dir), "{} not exists".format(root_dir)
                  for root, _, fnames in sorted(os.walk(root_dir)):
              Severity: Minor
              Found in oil/datasetup/celeba.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

              Function __call__ has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
              Open

                  def __call__(self,cfg,i=None):
                      try:
                          cfg.pop('local_rank',None) #TODO: properly handle distributed
                          resume = cfg.pop('resume',False)
                          save = cfg.pop('save',False)
              Severity: Minor
              Found in oil/tuning/study.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

              Function _process_worker has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

              def _process_worker(call_queue, result_queue,gpu_set,gpu_pool):
                  """Evaluates calls from call_queue and places the results in result_queue.
                  This worker is run in a separate process.
                  Args:
                      call_queue: A multiprocessing.Queue of _CallItems that will be read and
              Severity: Minor
              Found in oil/tuning/localGpuExecutor.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

              Function _sample_config has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

              def _sample_config(config_spec,cfg_all):
                  cfg = {}
                  more_work = False
                  for k,v in config_spec.items():
                      if isinstance(v,dict):
              Severity: Minor
              Found in oil/tuning/configGenerator.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

              Function __init__ has 27 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  def __init__(self, numClasses=10):
                      super().__init__()
                      self.numClasses = numClasses
                      self.activation = nn.LeakyReLU(0.1)
                      self.conv1a = nn.Conv2d(3, 96, 3, padding=1)
              Severity: Minor
              Found in oil/architectures/img_classifiers/networkparts.py - About 1 hr to fix

                Function __init__ has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    def __init__(self, num_targets=10):
                        super().__init__()
                        self.numClasses = num_targets
                        self.activation = nn.LeakyReLU(0.1)
                        self.conv1a = weight_norm(nn.Conv2d(3, 128, 3, padding=1))
                Severity: Minor
                Found in oil/architectures/img_classifiers/networkparts.py - About 1 hr to fix

                  Function __init__ has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      def __init__(self, numClasses=10):
                          super().__init__()
                          self.numClasses = numClasses
                          self.activation = nn.LeakyReLU(0.1)
                          self.conv1a = weight_norm(nn.Conv2d(3, 96, 3, padding=1))
                  Severity: Minor
                  Found in oil/architectures/img_classifiers/networkparts.py - About 1 hr to fix

                    Function __init__ has 8 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                        def __init__(self, model, dataloaders, opt_constr=optim.Adam, lr_sched = lambda e: 1, 
                    Severity: Major
                    Found in oil/model_trainers/trainer.py - About 1 hr to fix

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

                          def __init__(self, size):
                              if isinstance(size, numbers.Number):
                                  self.size = (int(size), int(size))
                              else:
                                  self.size = size
                      Severity: Minor
                      Found in oil/datasetup/joint_transforms.py and 1 other location - About 55 mins to fix
                      oil/datasetup/joint_transforms.py on lines 91..94

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

                      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

                              if isinstance(size, numbers.Number):
                                  self.size = (int(size), int(size))
                              else:
                                  self.size = size
                      Severity: Minor
                      Found in oil/datasetup/joint_transforms.py and 1 other location - About 55 mins to fix
                      oil/datasetup/joint_transforms.py on lines 46..50

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

                      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 _add_call_item_to_queue has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                      Open

                      def _add_call_item_to_queue(pending_work_items,
                                                  work_ids,
                                                  call_queue):
                          """Fills call_queue with _WorkItems from pending_work_items.
                          This function never blocks.
                      Severity: Minor
                      Found in oil/tuning/localGpuExecutor.py - About 55 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 process_user_input has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                      Open

                          def process_user_input(self,executor):
                              inp = maybe_get_input()
                              if inp is None: return
                              if inp[:4]=="halt":pass
                              elif inp[:3]=="add":
                      Severity: Minor
                      Found in oil/tuning/study.py - About 55 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