How to use the dallinger.nodes.ReplicatorAgent function in dallinger

To help you get started, we’ve selected a few dallinger 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 Dallinger / Dallinger / tests / test_models.py View on Github external
def test_transmit_raises_if_no_connection_to_destination(self, db_session):
        net1 = models.Network()
        net2 = models.Network()
        agent1 = nodes.ReplicatorAgent(network=net1)
        agent2 = nodes.ReplicatorAgent(network=net2)

        info1 = models.Info(origin=agent1, contents="foo")
        info2 = models.Info(origin=agent1, contents="bar")
        self.add(db_session, info1, info2)

        with raises(ValueError) as excinfo:
            agent1.transmit(what=None, to_whom=agent2)
            assert excinfo.match("cannot transmit to {}".format(agent2))
github Dallinger / Dallinger / tests / test_models.py View on Github external
def test_node_outgoing_transmissions(self, db_session):
        net = models.Network()
        db_session.add(net)
        agent1 = nodes.ReplicatorAgent(network=net)
        agent2 = nodes.ReplicatorAgent(network=net)
        agent3 = nodes.ReplicatorAgent(network=net)
        self.add(db_session, agent1, agent2, agent3)
        db_session.commit()

        agent1.connect(whom=agent2)
        agent1.connect(whom=agent3)
        self.add(db_session, agent1, agent2, agent3)

        info1 = models.Info(origin=agent1, contents="foo")
        info2 = models.Info(origin=agent1, contents="bar")
        self.add(db_session, info1, info2)

        agent1.transmit(what=info1, to_whom=agent2)
        agent1.transmit(what=info2, to_whom=agent3)
        db_session.commit()
github Dallinger / Dallinger / tests / test_processes.py View on Github external
def test_moran_process_sexual(self, db_session):

        # Create a fully-connected network.
        net = networks.Network()
        db_session.add(net)
        db_session.commit()

        agent1 = nodes.ReplicatorAgent(network=net)
        agent2 = nodes.ReplicatorAgent(network=net)
        agent3 = nodes.ReplicatorAgent(network=net)

        agent1.connect(direction="both", whom=[agent2, agent3])
        agent2.connect(direction="both", whom=agent3)

        # Add a global source and broadcast to all the nodes.
        source = nodes.RandomBinaryStringSource(network=net)
        source.connect(direction="to", whom=net.nodes(type=Agent))

        source.create_information()

        for agent in net.nodes(type=Agent):
            source.transmit(to_whom=agent)
            agent.receive()

        # Run a Moran process for 100 steps.
        for i in range(100):
github Dallinger / Dallinger / tests / test_processes.py View on Github external
def test_moran_process_sexual(self, db_session):

        # Create a fully-connected network.
        net = networks.Network()
        db_session.add(net)
        db_session.commit()

        agent1 = nodes.ReplicatorAgent(network=net)
        agent2 = nodes.ReplicatorAgent(network=net)
        agent3 = nodes.ReplicatorAgent(network=net)

        agent1.connect(direction="both", whom=[agent2, agent3])
        agent2.connect(direction="both", whom=agent3)

        # Add a global source and broadcast to all the nodes.
        source = nodes.RandomBinaryStringSource(network=net)
        source.connect(direction="to", whom=net.nodes(type=Agent))

        source.create_information()

        for agent in net.nodes(type=Agent):
            source.transmit(to_whom=agent)
            agent.receive()

        # Run a Moran process for 100 steps.
github Dallinger / Dallinger / tests / test_models.py View on Github external
def test_node_incoming_transmissions(self, db_session):
        net = models.Network()
        db_session.add(net)
        agent1 = nodes.ReplicatorAgent(network=net)
        agent2 = nodes.ReplicatorAgent(network=net)
        agent3 = nodes.ReplicatorAgent(network=net)
        self.add(db_session, agent1, agent2, agent3)
        db_session.commit()

        agent1.connect(direction="from", whom=[agent2, agent3])
        self.add(db_session, agent1, agent2, agent3)

        info1 = models.Info(origin=agent2, contents="foo")
        info2 = models.Info(origin=agent3, contents="bar")
        self.add(db_session, info1, info2)

        agent2.transmit(what=info1, to_whom=agent1)
        agent3.transmit(what=info2, to_whom=agent1)
        db_session.commit()
github Dallinger / Dallinger / tests / test_models.py View on Github external
def test_node_outgoing_transmissions(self, db_session):
        net = models.Network()
        db_session.add(net)
        agent1 = nodes.ReplicatorAgent(network=net)
        agent2 = nodes.ReplicatorAgent(network=net)
        agent3 = nodes.ReplicatorAgent(network=net)
        self.add(db_session, agent1, agent2, agent3)
        db_session.commit()

        agent1.connect(whom=agent2)
        agent1.connect(whom=agent3)
        self.add(db_session, agent1, agent2, agent3)

        info1 = models.Info(origin=agent1, contents="foo")
        info2 = models.Info(origin=agent1, contents="bar")
        self.add(db_session, info1, info2)

        agent1.transmit(what=info1, to_whom=agent2)
        agent1.transmit(what=info2, to_whom=agent3)
        db_session.commit()
github Dallinger / Dallinger / tests / test_sources.py View on Github external
def test_broadcast_random_binary_string_source(self, db_session):
        net = models.Network()
        self.add(db_session, net)
        source = nodes.RandomBinaryStringSource(network=net)
        agent1 = nodes.ReplicatorAgent(network=net)
        agent2 = nodes.ReplicatorAgent(network=net)
        db_session.add(agent1)
        db_session.add(agent2)
        db_session.commit()
        source.connect(whom=agent1)
        source.connect(whom=agent2)
        self.add(db_session, source, agent1, agent2)

        source.transmit(what=source.create_information())
        db_session.commit()

        agent1.receive()
        agent2.receive()
        db_session.commit()

        assert agent1.infos()[0].contents in ["00", "01", "10", "11"]
github Dallinger / Dallinger / tests / test_models.py View on Github external
def test_transmit_to_class_finds_nodes_in_network(self, db_session):
        net = models.Network()
        agent1 = nodes.ReplicatorAgent(network=net)
        agent2 = nodes.ReplicatorAgent(network=net)
        agent1.connect(whom=agent2)

        info1 = models.Info(origin=agent1, contents="foo")
        self.add(db_session, info1)
        transmissions = agent1.transmit(what=info1, to_whom=nodes.ReplicatorAgent)
        assert len(transmissions) == 1
        assert transmissions[0].origin is agent1
        assert transmissions[0].destination is agent2
github Dallinger / Dallinger / tests / test_models.py View on Github external
def test_transmission_order(self, db_session):
        net = models.Network()
        db_session.add(net)
        agent1 = nodes.ReplicatorAgent(network=net)
        agent2 = nodes.ReplicatorAgent(network=net)
        agent3 = nodes.ReplicatorAgent(network=net)
        self.add(db_session, agent1, agent2, agent3)
        db_session.commit()

        agent1.connect(whom=agent2)
        agent1.connect(whom=agent3)
        self.add(db_session, agent1, agent2, agent3)

        info1 = models.Info(origin=agent1, contents="foo")
        info2 = models.Info(origin=agent1, contents="bar")
        info3 = models.Info(origin=agent1, contents="baz")
        info4 = models.Info(origin=agent1, contents="spam")
        self.add(db_session, info1, info2, info3, info4)

        agent1.transmit(what=info1, to_whom=agent2)
        agent2.receive()
github Dallinger / Dallinger / tests / test_processes.py View on Github external
def test_moran_process_sexual(self, db_session):

        # Create a fully-connected network.
        net = networks.Network()
        db_session.add(net)
        db_session.commit()

        agent1 = nodes.ReplicatorAgent(network=net)
        agent2 = nodes.ReplicatorAgent(network=net)
        agent3 = nodes.ReplicatorAgent(network=net)

        agent1.connect(direction="both", whom=[agent2, agent3])
        agent2.connect(direction="both", whom=agent3)

        # Add a global source and broadcast to all the nodes.
        source = nodes.RandomBinaryStringSource(network=net)
        source.connect(direction="to", whom=net.nodes(type=Agent))

        source.create_information()

        for agent in net.nodes(type=Agent):
            source.transmit(to_whom=agent)
            agent.receive()