Skip to content

Commit

Permalink
Reuse network topologies between sub-experiments
Browse files Browse the repository at this point in the history
Fixes the issue #50 .

Signed-off-by: Andres Correa Casablanca <[email protected]>
  • Loading branch information
Andres Correa Casablanca committed Jun 5, 2019
1 parent 349e619 commit 6e0bba1
Showing 1 changed file with 56 additions and 11 deletions.
67 changes: 56 additions & 11 deletions experiments/notebooks/real_nodes_forking_01.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@
"from itertools import product as cartesian_product \n",
"from pathlib import Path\n",
"\n",
"from experiments.forking_simulation import ForkingSimulation"
"from experiments.forking_simulation import ForkingSimulation\n",
"from experiments.graph import create_network_graph"
]
},
{
Expand Down Expand Up @@ -178,6 +179,30 @@
"target_spacings = [4, 8, 12, 16] # Expected averate time between blocks\n",
"time_steps = [1, 2, 4, 6, 8] # Time granularity used to generate block hashes\n",
"latencies = [0, 0.1, 0.5, 1.0] # Block propagation delays\n",
"num_network_topologies = 3 # How many networks will be used to experiment with other parameters\n",
"\n",
"# We create a list of network topologies for each graph size, and not for each settings combination.\n",
"network_topologies = {\n",
" graph_size: [\n",
" create_network_graph(\n",
" num_nodes=graph_size,\n",
" num_outbound_connections=8,\n",
" max_inbound_connections=125,\n",
" graph_model='preferential_attachment'\n",
" ) for _ in range(num_network_topologies)\n",
" ]\n",
" for graph_size in {\n",
" num_proposer_nodes + num_validator_nodes + num_relay_nodes for (\n",
" num_proposer_nodes,\n",
" num_validator_nodes,\n",
" num_relay_nodes\n",
" ) in cartesian_product(\n",
" num_proposer_nodes_values,\n",
" num_validator_nodes_values,\n",
" num_relay_nodes_values,\n",
" )\n",
" }\n",
"}\n",
"\n",
"settings_tuples = list(cartesian_product(\n",
" num_proposer_nodes_values,\n",
Expand All @@ -190,22 +215,32 @@
"\n",
"settings_tuples = sorted([\n",
" (\n",
" num_proposer_nodes_values,\n",
" num_validator_nodes_values,\n",
" num_relay_nodes_values,\n",
" num_proposer_nodes,\n",
" num_validator_nodes,\n",
" num_relay_nodes,\n",
" target_spacings,\n",
" time_steps,\n",
" latencies\n",
" latencies,\n",
" graph_id, # Just used to create directory names\n",
" graph_edges # Besides filtering, we also add this\n",
" )\n",
" for (\n",
" num_proposer_nodes_values,\n",
" num_validator_nodes_values,\n",
" num_relay_nodes_values,\n",
" num_proposer_nodes,\n",
" num_validator_nodes,\n",
" num_relay_nodes,\n",
" target_spacings,\n",
" time_steps,\n",
" latencies\n",
" ) in settings_tuples\n",
" \n",
" # That's like a nested loop, but \"unrolled\" in the list comprehension\n",
" # We keep the graph id to construct directory names\n",
" for graph_id, graph_edges in enumerate(network_topologies[\n",
" num_proposer_nodes +\n",
" num_validator_nodes +\n",
" num_relay_nodes\n",
" ])\n",
" \n",
" if (\n",
" time_steps < target_spacings and\n",
" target_spacings % time_steps == 0\n",
Expand Down Expand Up @@ -248,11 +283,21 @@
"\n",
"# We generate a dataset per settings tuple\n",
"for c, settings in enumerate(settings_tuples):\n",
" num_proposer_nodes, num_validator_nodes, num_relay_nodes, target_spacing, time_step, latency = settings\n",
" (\n",
" num_proposer_nodes,\n",
" num_validator_nodes,\n",
" num_relay_nodes,\n",
" target_spacing,\n",
" time_step,\n",
" latency,\n",
" graph_id,\n",
" graph_edges\n",
" ) = settings\n",
"\n",
" # Each simulation stores results in a different path\n",
" result_directory = results_path.joinpath(\n",
" '_'.join(str(v) for v in settings)\n",
" # We discard `graph_edges` to construct the directory name\n",
" '_'.join(str(v) for v in settings[:-1])\n",
" ).resolve()\n",
"\n",
" # Previous data will be overwritten\n",
Expand All @@ -275,7 +320,7 @@
" num_relay_nodes=num_relay_nodes,\n",
" simulation_time=simulation_time,\n",
" sample_time=sample_time,\n",
" graph_model=graph_model,\n",
" graph_edges=graph_edges,\n",
" block_time_seconds=target_spacing,\n",
" block_stake_timestamp_interval_seconds=time_step,\n",
" network_stats_file_name=network_stats_filename,\n",
Expand Down

0 comments on commit 6e0bba1

Please sign in to comment.