How to use the merlin.common.sample_index.SampleIndex function in merlin

To help you get started, we’ve selected a few merlin examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github LLNL / merlin / merlin / common / sample_index.py View on Github external
def __str__(self):
        """String representation."""
        SampleIndex.depth = SampleIndex.depth + 1
        if self.is_leaf:
            result = (
                ("   " * SampleIndex.depth)
                + f"{self.address}: BUNDLE {self.leafid} MIN {self.min} MAX {self.max}\n"
            )
        else:
            result = (
                ("   " * SampleIndex.depth)
                + f"{self.address}: DIRECTORY MIN {self.min} MAX {self.max} NUM_BUNDLES {self.num_bundles}\n"
            )
            for child_val in self.children.values():
                result += str(child_val)
        SampleIndex.depth = SampleIndex.depth - 1
        return result
github LLNL / merlin / merlin / merlin_json.py View on Github external
if isinstance(obj, ExecutionGraph):
            result = {}
            for k, v in obj.__dict__.items():
                result[k] = self.default(v, lvl + 1)
            return std_json.dumps({"__ExecutionGraph__": result})
        if isinstance(obj, MerlinDAG):
            result = {}
            for k, v in obj.__dict__.items():
                result[k] = self.default(v, lvl + 1)
            return std_json.dumps({"__MerlinDAG__": result})
        if isinstance(obj, MerlinStep):
            result = {}
            for k, v in obj.__dict__.items():
                result[k] = self.default(v, lvl + 1)
            return std_json.dumps({"__MerlinStep__": result})
        if isinstance(obj, SampleIndex):
            result = {}
            for k, v in obj.__dict__.items():
                result[k] = self.default(v, lvl + 1)
            return std_json.dumps({"__SampleIndex__": result})
        return kombu_JSONEncoder().default(obj)
github LLNL / merlin / merlin / common / sample_index_factory.py View on Github external
max_sample = -MAX_SAMPLE
    num_bundles = 0
    with cd(path):
        with open("sample_index.txt", "r") as _file:
            token = _file.readline()
            while token:
                parsed_token = parse(
                    "{type}:{ID}\tname:{name}\tsamples:[{min:d},{max:d})\n", token
                )
                if parsed_token["type"] == "DIR":
                    subhierarchy = read_hierarchy(parsed_token["name"])
                    subhierarchy.address = parsed_token["ID"]
                    num_bundles += subhierarchy.num_bundles
                    children[parsed_token["ID"]] = subhierarchy
                if parsed_token["type"] == "BUNDLE":
                    children[parsed_token["ID"]] = SampleIndex(
                        parsed_token["min"],
                        parsed_token["max"],
                        {},
                        parsed_token["name"],
                        address=parsed_token["ID"],
                    )
                    num_bundles += 1
                min_sample = min(min_sample, parsed_token["min"])
                max_sample = max(max_sample, parsed_token["max"])
                token = _file.readline()
    top_index = SampleIndex(
        min_sample, max_sample, children, path, leafid=-1, num_bundles=num_bundles
    )
    return top_index
github LLNL / merlin / merlin / common / sample_index_factory.py View on Github external
bundle_id += children[child_address].num_bundles
        else:
            # Append a bundle file child.
            children[child_address] = SampleIndex(
                child_min_sample_id,
                child_max_sample_id,
                {},
                f"samples{child_min_sample_id}-{child_max_sample_id}.ext",
                leafid=bundle_id,
                address=child_address,
            )
            bundle_id += 1
        child_id += 1
    num_bundles = bundle_id - start_bundle_id
    return SampleIndex(
        min_sample, max_sample, children, root, num_bundles=num_bundles, address=address
    )
github LLNL / merlin / merlin / common / sample_index_factory.py View on Github external
subhierarchy.address = parsed_token["ID"]
                    num_bundles += subhierarchy.num_bundles
                    children[parsed_token["ID"]] = subhierarchy
                if parsed_token["type"] == "BUNDLE":
                    children[parsed_token["ID"]] = SampleIndex(
                        parsed_token["min"],
                        parsed_token["max"],
                        {},
                        parsed_token["name"],
                        address=parsed_token["ID"],
                    )
                    num_bundles += 1
                min_sample = min(min_sample, parsed_token["min"])
                max_sample = max(max_sample, parsed_token["max"])
                token = _file.readline()
    top_index = SampleIndex(
        min_sample, max_sample, children, path, leafid=-1, num_bundles=num_bundles
    )
    return top_index
github LLNL / merlin / merlin / common / sample_index.py View on Github external
raise KeyError

        delete_me = None
        for child_val in list(self.children.values()):
            if full_address[0 : len(child_val.address)] == child_val.address:
                if child_val.address == full_address:
                    delete_me = full_address
                    break

                child_val[full_address] = sub_tree
                return

        # Replace if we already have something at this address.
        if delete_me is not None:
            self.children.__delitem__(full_address)
            SampleIndex.check_valid_addresses_for_insertion(full_address, sub_tree)
            self.children[full_address] = sub_tree
            return
        raise KeyError
github LLNL / merlin / merlin / common / sample_index_factory.py View on Github external
# Append an SampleIndex sub-hierarchy child.
            children[child_address] = create_hierarchy_from_max_sample(
                child_max_sample_id,
                bundle_size,
                directory_sizes[1:],
                root=child_dir,
                min_sample=child_min_sample_id,
                start_bundle_id=bundle_id,
                address=child_address,
                n_digits=n_digits,
            )

            bundle_id += children[child_address].num_bundles
        else:
            # Append a bundle file child.
            children[child_address] = SampleIndex(
                child_min_sample_id,
                child_max_sample_id,
                {},
                f"samples{child_min_sample_id}-{child_max_sample_id}.ext",
                leafid=bundle_id,
                address=child_address,
            )
            bundle_id += 1
        child_id += 1
    num_bundles = bundle_id - start_bundle_id
    return SampleIndex(
        min_sample, max_sample, children, root, num_bundles=num_bundles, address=address
    )