How to use the hivemind.compositehivemind.CompositeHivemind function in hivemind

To help you get started, we’ve selected a few hivemind 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 ValyrianTech / BitcoinSpellbook / hivemind / listcomposite.py View on Github external
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from .compositehivemind import CompositeHivemind
from .hivemind import HivemindState
from helpers.hivemindhelpers import get_hivemind_state_hash
from helpers.loghelpers import LOG


class ListComposite(CompositeHivemind):
    def get_result(self):
        if not all(key in self.components for key in ('items', 'max_length')):
            LOG.error('List Composite hivemind does not contain all necessary components!')
            return

        # Get the items for the list
        hivemind_id, question_index = self.components['items']
        items_hivemind_state_hash = get_hivemind_state_hash(hivemind_id=hivemind_id)
        items_hivemind_state = HivemindState(multihash=items_hivemind_state_hash)

        # consensus type should be 'Ranked'
        if items_hivemind_state._hivemind_issue.consensus_type != 'Ranked':
            raise Exception('items hivemind does not have a Ranked consensus type')

        items = items_hivemind_state.get_consensus(question_index=question_index)
github ValyrianTech / BitcoinSpellbook / hivemind / dictionarycomposite.py View on Github external
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from .compositehivemind import CompositeHivemind
from .hivemind import HivemindState
from helpers.hivemindhelpers import get_hivemind_state_hash
from helpers.loghelpers import LOG

class DictionaryComposite(CompositeHivemind):
    def get_result(self):
        ret = {}
        for component_name, (hivemind_id, question_index) in self.components.items():
            hivemind_state_hash = get_hivemind_state_hash(hivemind_id=hivemind_id)
            hivemind_state = HivemindState(multihash=hivemind_state_hash)
            value = hivemind_state.get_consensus(question_index=question_index)
            LOG.info('Dictionary composite component %s: %s' % (component_name, value))
            ret[component_name] = value

        return ret
github ValyrianTech / BitcoinSpellbook / hivemind / distributioncomposite.py View on Github external
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from .compositehivemind import CompositeHivemind
from .hivemind import HivemindState
from helpers.hivemindhelpers import get_hivemind_state_hash
from helpers.loghelpers import LOG


class DistributionComposite(CompositeHivemind):
    def get_result(self):
        if not all(key in self.components for key in ('priority', 'number_of_recipients', 'budget', 'budget_slope')):
            LOG.error('Distribution Composite hivemind does not contain all necessary components!')
            return

        priority_state_hash = get_hivemind_state_hash(self.components['priority'][0])
        number_of_recipients_state_hash = get_hivemind_state_hash(self.components['number_of_recipients'][0])
        budget_state_hash = get_hivemind_state_hash(self.components['budget'][0])
        budget_slope_state_hash = get_hivemind_state_hash(self.components['budget_slope'][0])

        priority_state = HivemindState(multihash=priority_state_hash)
        number_of_recipients_state = HivemindState(multihash=number_of_recipients_state_hash)
        budget_state = HivemindState(multihash=budget_state_hash)
        budget_slope_state = HivemindState(multihash=budget_slope_state_hash)

        # todo check if there is a consensus on each value

hivemind

Decentralized deep learning in PyTorch

MIT
Latest version published 1 year ago

Package Health Score

62 / 100
Full package analysis

Similar packages