Skip to content

Commit b55c8f6

Browse files
committed
Bring back commented test _map_consensus_guarantees
1 parent cfc0b9f commit b55c8f6

File tree

1 file changed

+44
-42
lines changed

1 file changed

+44
-42
lines changed

pallets/subtensor/src/tests/epoch.rs

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2737,46 +2737,48 @@ fn test_blocks_since_last_step() {
27372737
});
27382738
}
27392739

2740-
// // Map the retention graph for consensus guarantees with an single epoch on a graph with 512 nodes, of which the first 64 are validators, the graph is split into a major and minor set, each setting specific weight on itself and the complement on the other.
2741-
// //
2742-
// // ```import torch
2743-
// // import matplotlib.pyplot as plt
2744-
// // from matplotlib.pyplot import cm
2745-
// // %matplotlib inline
2746-
// //
2747-
// // with open('finney_consensus_0.4.txt') as f: # test output saved to finney_consensus.txt
2748-
// // retention_map = eval(f.read())
2749-
// //
2750-
// // major_ratios = {}
2751-
// // avg_weight_devs = {}
2752-
// // for major_stake, major_weight, minor_weight, avg_weight_dev, major_ratio in retention_map:
2753-
// // major_stake = f'{major_stake:.2f}'
2754-
// // maj, min = int(round(50 * major_weight)), int(round(50 * minor_weight))
2755-
// // avg_weight_devs.setdefault(major_stake, torch.zeros((51, 51)))
2756-
// // avg_weight_devs[major_stake][maj][min] = avg_weight_dev
2757-
// // major_ratios.setdefault(major_stake, torch.zeros((51, 51)))
2758-
// // major_ratios[major_stake][maj][min] = major_ratio
2759-
// //
2760-
// // _x = torch.linspace(0, 1, 51); _y = torch.linspace(0, 1, 51)
2761-
// // x, y = torch.meshgrid(_x, _y, indexing='ij')
2762-
// //
2763-
// // fig = plt.figure(figsize=(6, 6), dpi=70); ax = fig.gca()
2764-
// // ax.set_xticks(torch.arange(0, 1, 0.05)); ax.set_yticks(torch.arange(0, 1., 0.05))
2765-
// // ax.set_xticklabels([f'{_:.2f}'[1:] for _ in torch.arange(0, 1., 0.05)])
2766-
// // plt.grid(); plt.rc('grid', linestyle="dotted", color=[0.85, 0.85, 0.85])
2767-
// //
2768-
// // isolate = ['0.60']; stakes = [0.51, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 0.99]
2769-
// // colors = cm.viridis(torch.linspace(0, 1, len(stakes) + 1))
2770-
// // for i, stake in enumerate(stakes):
2771-
// // contours = plt.contour(x, y, major_ratios[f'{stake:.2f}'], levels=[0., stake], colors=[colors[i + 1]])
2772-
// // if f'{stake:.2f}' in isolate:
2773-
// // contours.collections[1].set_linewidth(3)
2774-
// // plt.clabel(contours, inline=True, fontsize=10)
2775-
// //
2776-
// // plt.title(f'Major emission [$stake_{{maj}}=emission_{{maj}}$ retention lines]')
2777-
// // plt.ylabel('Minor self-weight'); plt.xlabel('Major self-weight'); plt.show()
2778-
// // ```
2779-
// // #[test]
2740+
// Map the retention graph for consensus guarantees with an single epoch on a graph with 512 nodes,
2741+
// of which the first 64 are validators, the graph is split into a major and minor set, each setting
2742+
// specific weight on itself and the complement on the other.
2743+
//
2744+
// ```import torch
2745+
// import matplotlib.pyplot as plt
2746+
// from matplotlib.pyplot import cm
2747+
// %matplotlib inline
2748+
//
2749+
// with open('finney_consensus_0.4.txt') as f: # test output saved to finney_consensus.txt
2750+
// retention_map = eval(f.read())
2751+
//
2752+
// major_ratios = {}
2753+
// avg_weight_devs = {}
2754+
// for major_stake, major_weight, minor_weight, avg_weight_dev, major_ratio in retention_map:
2755+
// major_stake = f'{major_stake:.2f}'
2756+
// maj, min = int(round(50 * major_weight)), int(round(50 * minor_weight))
2757+
// avg_weight_devs.setdefault(major_stake, torch.zeros((51, 51)))
2758+
// avg_weight_devs[major_stake][maj][min] = avg_weight_dev
2759+
// major_ratios.setdefault(major_stake, torch.zeros((51, 51)))
2760+
// major_ratios[major_stake][maj][min] = major_ratio
2761+
//
2762+
// _x = torch.linspace(0, 1, 51); _y = torch.linspace(0, 1, 51)
2763+
// x, y = torch.meshgrid(_x, _y, indexing='ij')
2764+
//
2765+
// fig = plt.figure(figsize=(6, 6), dpi=70); ax = fig.gca()
2766+
// ax.set_xticks(torch.arange(0, 1, 0.05)); ax.set_yticks(torch.arange(0, 1., 0.05))
2767+
// ax.set_xticklabels([f'{_:.2f}'[1:] for _ in torch.arange(0, 1., 0.05)])
2768+
// plt.grid(); plt.rc('grid', linestyle="dotted", color=[0.85, 0.85, 0.85])
2769+
//
2770+
// isolate = ['0.60']; stakes = [0.51, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 0.99]
2771+
// colors = cm.viridis(torch.linspace(0, 1, len(stakes) + 1))
2772+
// for i, stake in enumerate(stakes):
2773+
// contours = plt.contour(x, y, major_ratios[f'{stake:.2f}'], levels=[0., stake], colors=[colors[i + 1]])
2774+
// if f'{stake:.2f}' in isolate:
2775+
// contours.collections[1].set_linewidth(3)
2776+
// plt.clabel(contours, inline=True, fontsize=10)
2777+
//
2778+
// plt.title(f'Major emission [$stake_{{maj}}=emission_{{maj}}$ retention lines]')
2779+
// plt.ylabel('Minor self-weight'); plt.xlabel('Major self-weight'); plt.show()
2780+
// ```
2781+
// #[test]
27802782
// fn _map_consensus_guarantees() {
27812783
// let netuid: u16 = 1;
27822784
// let network_n: u16 = 512;
@@ -2811,10 +2813,10 @@ fn test_blocks_since_last_step() {
28112813
// network_n as usize,
28122814
// interleave as usize,
28132815
// );
2814-
2816+
//
28152817
// new_test_ext(1).execute_with(|| {
28162818
// init_run_epochs(netuid, network_n, &validators, &servers, epochs, 1, true, &stake, true, &weights, true, false, 0, true);
2817-
2819+
//
28182820
// let mut major_emission: I64F64 = I64F64::from_num(0);
28192821
// let mut minor_emission: I64F64 = I64F64::from_num(0);
28202822
// for set in vec![major_validators, major_servers] {

0 commit comments

Comments
 (0)