How to use scenario - 10 common examples

To help you get started, we’ve selected a few scenario 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 SubstraFoundation / distributed-learning-contributivity / tests.py View on Github external
def create_scenario(create_MultiPartnerLearning, create_Dataset, create_partner_list):
    params = {"dataset_name": "cifar10", "partners_count":3, "amounts_per_partner": [0.2, 0.5, 0.3], "samples_split_option": ["basic","random"], "multi_partner_learning_aproach":"fedavg", "aggregation_weighting": "uniform", "methods": ["Shapley values", "Independent scores"], "gradient_updates_per_pass_count": 5}

    experiment_path = Path('/home/garibou/Documents/distributed-learning-contributivity/experiments/test_unitaire')

    scenar = Scenario(
            params=params,
            experiment_path=experiment_path,
            scenario_id=0,
            n_repeat=1
            )

    scenar.mpl = create_MultiPartnerLearning
    scenar.dataset

    yield scenar
github heronyang / airport-simulation / tests / test_routing_expert.py View on Github external
def test_sfo_terminal_2_all(self):
        airport_code = "sfo-terminal-2"

        # Sets up the airport
        self.airport = Airport.create(airport_code)

        # Sets up the scenario
        self.scenario = Scenario.create(airport_code,
                                        self.airport.surface)

        links = self.airport.surface.links
        nodes = self.airport.surface.nodes

        routing_expert = RoutingExpert(links, nodes, True)
        runway_start = self.airport.surface.get_link("10R/28L").start

        # Checks the gate that is far from the runway (G53)
        gate_names = ["50", "55", "53", "52", "54A", "51A", "51B", "54B",
                      "56B", "56A", "57", "59", "58B", "58A"]
        for gate_name in gate_names:
            gate = self.airport.surface.get_node(gate_name)
            route = routing_expert.get_shortest_route(gate, runway_start)
            # Make sure they all have a route to go to the runway
            self.assertTrue(len(route.nodes) >= 2)
github heronyang / airport-simulation / tests / test_routing_expert.py View on Github external
def test_sfo_terminal_2_furthest(self):
        airport_code = "sfo-terminal-2"

        # Sets up the airport
        self.airport = Airport.create(airport_code)

        # Sets up the scenario
        self.scenario = Scenario.create(airport_code,
                                        self.airport.surface)

        links = self.airport.surface.links
        nodes = self.airport.surface.nodes

        routing_expert = RoutingExpert(links, nodes, True)
        runway_start = self.airport.surface.get_link("10R/28L").start

        # Checks the gate that is far from the runway (G53)
        gate_53 = self.airport.surface.get_node("53")

        routeG53to10R = \
            routing_expert.get_shortest_route(gate_53, runway_start)
        self.assertAlmostEqual(routeG53to10R.distance, 10014.749180929799, 5)
        self.assertEqual(len(routeG53to10R.nodes), 39)
        self.assertEqual(len(routeG53to10R.links), 38)
github heronyang / airport-simulation / tests / test_routing_expert.py View on Github external
def test_sfo_terminal_2_closest(self):
        airport_code = "sfo-terminal-2"

        # Sets up the airport
        self.airport = Airport.create(airport_code)

        # Sets up the scenario
        self.scenario = Scenario.create(airport_code,
                                        self.airport.surface)

        links = self.airport.surface.links
        nodes = self.airport.surface.nodes

        routing_expert = RoutingExpert(links, nodes, True)
        runway_start = self.airport.surface.get_link("10R/28L").start

        # Checks the gate that is near to the runway (G58B)
        gate_58B = self.airport.surface.get_node("58B")
        routeG58Bto10R = \
            routing_expert.get_shortest_route(gate_58B, runway_start)

        self.assertAlmostEqual(routeG58Bto10R.distance, 8198.5613013809, 5)
        self.assertEqual(len(routeG58Bto10R.nodes), 32)
        self.assertEqual(len(routeG58Bto10R.links), 31)
github heronyang / airport-simulation / tests / test_routing_expert.py View on Github external
def test_simple_data(self):
        airport_code = "simple"

        # Sets up the airport
        self.airport = Airport.create(airport_code)

        # Sets up the scenario
        self.scenario = Scenario.create(airport_code,
                                        self.airport.surface)

        links = self.airport.surface.links
        nodes = self.airport.surface.nodes

        # Sets up the routing expert monitoring the airport surface
        routing_expert = RoutingExpert(links, nodes, False)

        routeG3toR1 = routing_expert.get_shortest_route(nodes[2],
                                                        links[0].start)

        self.assertEqual(len(routeG3toR1.nodes), 8)
        self.assertAlmostEqual(routeG3toR1.distance, 1352.6500035604972, 5)
github drf / amsn2 / pymsn / pymsn / service / AddressBook / address_book.py View on Github external
def add_contact_to_group(self, group, contact):
        def callback():
            contact._add_group_ownership(group)
            self.emit('group-contact-added', group, contact)
        ac = scenario.GroupContactAddScenario(self._ab,
                (callback,),
                (self.__common_errback,))
        ac.group_guid = group.id
        ac.contact_guid = contact.id
        ac()
github drf / amsn2 / pymsn / pymsn / service / AddressBook / address_book.py View on Github external
def unblock_contact(self, contact):
        def callback(memberships):
            contact._set_memberships(memberships)
            self.emit('contact-unblocked', contact)
        uc = scenario.UnblockContactScenario(self._sharing,
                (callback,),
                (self.__common_errback,))
        uc.account = contact.account
        uc.network = contact.network_id
        uc.membership = contact.memberships
        uc()
github drf / amsn2 / pymsn / pymsn / service / AddressBook / address_book.py View on Github external
def accept_contact_invitation(self, pending_contact, add_to_contact_list=True):
        def callback(contact_infos, memberships):
            pending_contact.freeze_notify()
            pending_contact._id = contact_infos.Id
            pending_contact._cid = contact_infos.CID
            pending_contact._set_memberships(memberships)
            pending_contact.thaw_notify()
            self.emit('contact-accepted', pending_contact)
        ai = scenario.AcceptInviteScenario(self._ab, self._sharing,
                 (callback,),
                 (self.__common_errback,))
        ai.account = pending_contact.account
        ai.network = pending_contact.network_id
        ai.memberships = pending_contact.memberships
        ai.add_to_contact_list = add_to_contact_list
        ai()
github Orange-OpenSource / diafuzzer / fuzz-proprietary-avps.py View on Github external
def testScn(host, port, scenario):
    # run once in order to capture exchanged pdus
    f = sk.socket(sk.AF_INET, sk.SOCK_STREAM)
    f.connect((host, port))
    (exc_info, msgs) = dwr_handler(scenario, f, local_hostname, local_realm)
    if exc_info is not None:
        print >> sys.stderr, '[ERROR] The scenario raised %r' % exc_info
        sys.exit(1)
    f.close()

    return msgs
github Orange-OpenSource / diafuzzer / fuzz.py View on Github external
if exc_info is not None:
        logging.warning('scenario %s raised: %s' % (fuzz.description, exc_info))
      f.close()

  elif args.mode == 'server':
    srv = sk.socket(sk.AF_INET, sk.SOCK_STREAM, sk.IPPROTO_SCTP)
    if args.local_addresses:
      addrs = [(a, int(args.local_port)) for a in args.local_addresses]
      ret = sctp.bindx(srv, addrs)
      assert(ret == 0)
    else:
      srv.bind(('0.0.0.0', args.local_port))
    srv.listen(64)

    (f,_) = srv.accept()
    (exc_info, msgs) = dwr_handler(scenario, f, args.local_hostname, args.local_realm)
    if exc_info is not None:
      logging.warning('vanilla scenario raised: %s' % (exc_info))
      sys.exit(1)
    f.close()

    for (m, is_sent) in msgs:
      Directory.tag(m)

    fuzzs = analyze(msgs)
    logging.info('generated %d scenarios of fuzzing' % len(fuzzs))

    for fuzz in fuzzs:
      (f,_) = srv.accept()
      (exc_info, msgs) = dwr_handler(scenario, f, args.local_hostname, args.local_realm, fuzz)
      if exc_info is not None:
        logging.warning('scenario %s raised: %s' % (fuzz.description, exc_info))