code: def find_minimum_sparsity(matrix, search_function, **kwargs):
      duration = 0
      min_sparsity = 50
      max_sparsity = 100
      sparsity = 75
      verbosity = 0
      if "verbosity" in kwargs:
          verbosity = kwargs["verbosity"]
  
      while min_sparsity < max_sparsity:
          if verbosity > 5:
              print(
                  f"\tlooking now at {sparsity} (between {min_sparsity} and {max_sparsity})"
              )
  
          # prepare unstructured sparse matrix, get row sparsity magnitude
          tmp_result = unstructured_prune(result, sparsity / 100.0)
          local_unpruned_magnitude = np.sum(np.abs(tmp_result))
          local_unstructured_rows_magnitude = (
              magnitude_after_pruning_rows(tmp_result, rate=0.5)
          )
  
          # quick check to see if this sparsity is trivially too low
          if (
              local_unstructured_rows_magnitude * 1.0001
              < local_unpruned_magnitude
          ):
              if verbosity > 5:
                  print(
                      f"Skipping sparsity {sparsity} since there's no perfect permutation (unstructured mag {local_unpruned_magnitude} is larger than sparse rows {local_unstructured_rows_magnitude})."
                  )
              min_sparsity = sparsity + 1
              sparsity = int(
                  min_sparsity + (max_sparsity - min_sparsity) / 2.0
              )
              continue
  
          tmp_result, tmp_duration, found_permutation = search_function(
              tmp_result, **kwargs
          )
          duration += tmp_duration
          nonzeros = np.count_nonzero(tmp_result)
          tmp_result = apply_2_to_4(tmp_result)
          nonzeros_after_2to4 = np.count_nonzero(tmp_result)
          if (
              nonzeros == nonzeros_after_2to4
          ):  # found a winner, are we done?
              if verbosity > 3:
                  print(
                      f"Found an unstructured sparsity that we can turn into 2:4: {sparsity}"
                  )
  
              max_sparsity = sparsity
              if max_sparsity <= min_sparsity and verbosity > 0:
                  print(
                      f"Found the minimum unstructured sparsity that we can turn into 2:4: {sparsity}"
                  )
                  break
          else:
              if verbosity > 5:
                  print(
                      f"Unstructured sparsity {sparsity} was insufficient to produce 2:4 sparsity"
                  )
              min_sparsity = sparsity + 1
              if max_sparsity <= min_sparsity and verbosity > 0:
                  print(
                      f"Found the minimum unstructured sparsity that we can turn into 2:4: {max_sparsity}"
                  )
                  sparsity = max_sparsity
                  break
  
          sparsity = int(
              min_sparsity + (max_sparsity - min_sparsity) / 2.0
          )
  
      return sparsity, duration
  
file_path: apex/apex/contrib/sparsity/permutation_tests/permutation_test.py
imports: import numpy
  import time
  import sys
  from permutation_search_kernels.permutation_utilities import *
  from permutation_search_kernels.exhaustive_search import Exhaustive_Search
  from permutation_search_kernels.channel_swap import Channel_Swap
  import argparse
label_desc: Use image node_id 2 for calling a global function with example usage: find_minimum_sparsity(matrix, search_function) and returns: sparsity,  duration