How to use the syft.ID_PROVIDER.pop function in syft

To help you get started, we’ve selected a few syft 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 OpenMined / PySyft / test / workers / test_virtual.py View on Github external
def test_send_msg():
    """Tests sending a message with a specific ID

    This is a simple test to ensure that the BaseWorker interface
    can properly send/receive a message containing a tensor.
    """

    # get pointer to local worker
    me = sy.torch.hook.local_worker

    # create a new worker (to send the object to)
    worker_id = sy.ID_PROVIDER.pop()
    bob = VirtualWorker(sy.torch.hook, id=f"bob{worker_id}")

    # initialize the object and save it's id
    obj = torch.Tensor([100, 100])
    obj_id = obj.id

    # Send data to bob
    me.send_msg(messaging.ObjectMessage(obj), bob)

    # ensure that object is now on bob's machine
    assert obj_id in bob._objects
github OpenMined / PySyft / test / torch / test_federated_learning.py View on Github external
def setUp(self):
        hook = sy.TorchHook(torch, verbose=True)

        self.me = hook.local_worker
        self.me.is_client_worker = True

        instance_id = str(sy.ID_PROVIDER.pop())
        bob = sy.VirtualWorker(id=f"bob{instance_id}", hook=hook, is_client_worker=False)
        alice = sy.VirtualWorker(id=f"alice{instance_id}", hook=hook, is_client_worker=False)
        james = sy.VirtualWorker(id=f"james{instance_id}", hook=hook, is_client_worker=False)

        bob.add_workers([alice, james])
        alice.add_workers([bob, james])
        james.add_workers([bob, alice])

        self.hook = hook

        self.bob = bob
        self.alice = alice
        self.james = james

        # A Toy Dataset
        data = torch.tensor([[0, 0], [0, 1], [1, 0], [1, 1.0]], requires_grad=True)
github OpenMined / PySyft / test / torch / test_hook.py View on Github external
def test_pointer_found_exception(workers):
    ptr_id = syft.ID_PROVIDER.pop()
    pointer = PointerTensor(id=ptr_id, location=workers["alice"], owner=workers["me"])

    try:
        raise RemoteObjectFoundError(pointer)
    except RemoteObjectFoundError as err:
        err_pointer = err.pointer
        assert isinstance(err_pointer, PointerTensor)
        assert err_pointer.id == ptr_id
github OpenMined / PySyft / syft / frameworks / torch / tensors / interpreters / private.py View on Github external
):
        """ Initialize a Private tensor, which manages permissions restricting get operations.

            Args:
                owner (BaseWorker, optional): A BaseWorker object to specify the worker on which
                the tensor is located.
                id (string or int, optional): An optional string or integer id of the PrivateTensor.
                tags (set, optional): A set of tags to label this tensor.
                description (string, optional): A brief description about this tensor.
                allowed_users (Union, optional): User credentials.
                parents (tuple, optional): If it was generated by other tensors, it'll be referenced here.
                command (string, optional): If it was generated by some operation, it'll be registered here.
        """
        super().__init__(tags=tags, description=description)
        self.owner = owner
        self.id = id if id else syft.ID_PROVIDER.pop()
        self.child = None
        self.allowed_users = allowed_users
        self.parents = parents
        self.command = command
github OpenMined / PySyft / syft / messaging / plan.py View on Github external
def _execute_readable_plan(self, *args):
        # TODO: for now only one value is returned from a plan
        result_ids = [sy.ID_PROVIDER.pop()]

        plan_res = self.execute_plan(args, result_ids)

        return plan_res
github OpenMined / PySyft / syft / frameworks / torch / tensors / interpreters / abstract.py View on Github external
def _apply_args(hook_self, new_tensor, owner=None, id=None):

    if owner is None:
        owner = hook_self.local_worker

    if id is None:
        id = sy.ID_PROVIDER.pop()

    new_tensor.id = id
    new_tensor.owner = owner
github OpenMined / PySyft / syft / messaging / plan.py View on Github external
def _get_plan_output(self, result_ids, return_ptr=False):
        responses = []
        for return_id in result_ids:
            response = PointerTensor(
                location=self.owner, id_at_location=return_id, owner=self, id=sy.ID_PROVIDER.pop()
            )
            responses.append(response if return_ptr else response.get())

        if len(responses) == 1:
            return responses[0]

        return responses
github OpenMined / PySyft / syft / federated / train_config.py View on Github external
def _wrap_and_send_obj(self, obj, location):
        """Wrappers object and send it to location."""
        obj_with_id = pointers.ObjectWrapper(id=sy.ID_PROVIDER.pop(), obj=obj)
        obj_ptr = self.owner.send(obj_with_id, location)
        obj_id = obj_ptr.id_at_location
        return obj_ptr, obj_id