tensorflow/models

View on GitHub
research/efficient-hrl/context/context.py

Summary

Maintainability
F
3 days
Test Coverage

File context.py has 382 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# Copyright 2018 The TensorFlow Authors All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Severity: Minor
Found in research/efficient-hrl/context/context.py - About 5 hrs to fix

    Function _make_reward_fn has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

      def _make_reward_fn(self, reward_fns_list, reward_weights):
        """Returns a fn that computes rewards.
    
        Args:
          reward_fns_list: A fn or a list of reward fns.
    Severity: Minor
    Found in research/efficient-hrl/context/context.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 __init__ has 16 arguments (exceeds 4 allowed). Consider refactoring.
    Open

      def __init__(self,
    Severity: Major
    Found in research/efficient-hrl/context/context.py - About 2 hrs to fix

      Function __init__ has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

        def __init__(self,
                     tf_env,
                     context_ranges=None,
                     context_shapes=None,
                     state_indices=None,
      Severity: Minor
      Found in research/efficient-hrl/context/context.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 31 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def __init__(self,
                     tf_env,
                     context_ranges=None,
                     context_shapes=None,
                     state_indices=None,
      Severity: Minor
      Found in research/efficient-hrl/context/context.py - About 1 hr to fix

        Function _make_sampler_fn has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

          def _make_sampler_fn(self, sampler_cls_list, mode):
            """Returns a fn that samples a list of context vars.
        
            Args:
              sampler_cls_list: A list of sampler classes.
        Severity: Minor
        Found in research/efficient-hrl/context/context.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 compute_rewards has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

          def compute_rewards(self, mode, states, actions, rewards, next_states,
        Severity: Minor
        Found in research/efficient-hrl/context/context.py - About 45 mins to fix

          Function reset has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

            def reset(self, mode, agent=None, action_fn=None, state=None):
              """Returns ops that reset the context.
          
              Args:
                mode: a string representing the mode=[train, explore, eval].
          Severity: Minor
          Found in research/efficient-hrl/context/context.py - About 45 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 sample_contexts has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

            def sample_contexts(self, mode, batch_size, state=None, next_state=None,
          Severity: Minor
          Found in research/efficient-hrl/context/context.py - About 35 mins to fix

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

              def get_clip_fns(self):
                """Returns a list of clip fns for contexts.
            
                Returns:
                  A list of fns that clip context tensors.
            Severity: Minor
            Found in research/efficient-hrl/context/context.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

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

                      for _ in range(discounts_list[i].shape.ndims - ndims):
                        discounts_list[i] = tf.expand_dims(discounts_list[i], axis=-1)
            Severity: Major
            Found in research/efficient-hrl/context/context.py and 1 other location - About 2 hrs to fix
            research/efficient-hrl/context/context.py on lines 211..212

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

            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

                      for _ in range(rewards_list[i].shape.ndims - ndims):
                        rewards_list[i] = tf.expand_dims(rewards_list[i], axis=-1)
            Severity: Major
            Found in research/efficient-hrl/context/context.py and 1 other location - About 2 hrs to fix
            research/efficient-hrl/context/context.py on lines 213..214

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

            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

                  next_contexts = [
                      normalizer.apply(c) if normalizer is not None else c
                      for normalizer, c in zip(self._normalizers, next_contexts)
            Severity: Major
            Found in research/efficient-hrl/context/context.py and 1 other location - About 1 hr to fix
            research/efficient-hrl/context/context.py on lines 252..254

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

            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

                  contexts = [
                      normalizer.update_apply(c) if normalizer is not None else c
                      for normalizer, c in zip(self._normalizers, contexts)
            Severity: Major
            Found in research/efficient-hrl/context/context.py and 1 other location - About 1 hr to fix
            research/efficient-hrl/context/context.py on lines 256..258

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

            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

                if context_ranges is not None:
                  self.context_ranges = context_ranges
                else:
                  self.context_ranges = [None] * len(self._context_shapes)
            Severity: Major
            Found in research/efficient-hrl/context/context.py and 1 other location - About 1 hr to fix
            research/efficient-hrl/context/context.py on lines 90..93

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

            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

                if state_indices is not None:
                  self.state_indices = state_indices
                else:
                  self.state_indices = [None] * len(self._context_shapes)
            Severity: Major
            Found in research/efficient-hrl/context/context.py and 1 other location - About 1 hr to fix
            research/efficient-hrl/context/context.py on lines 75..78

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

            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

            There are no issues that match your filters.

            Category
            Status