Skip to content

Commit a3c2b71

Browse files
committed
fix epoch tests. not sure about values
1 parent 86fc7c9 commit a3c2b71

File tree

1 file changed

+66
-63
lines changed

1 file changed

+66
-63
lines changed

pallets/subtensor/src/tests/epoch.rs

+66-63
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ fn test_512_graph() {
713713
assert_eq!(SubtensorModule::get_dividends_for_uid(netuid, uid), 1023); // Note D = floor(1 / 64 * 65_535) = 1023
714714
assert_eq!(SubtensorModule::get_emission_for_uid(netuid, uid), 7812500); // Note E = 0.5 / 200 * 1_000_000_000 = 7_812_500
715715
assert_eq!(bonds[uid as usize][validator], 0.0);
716-
assert_eq!(bonds[uid as usize][server], I32F32::from_num(65_535));
716+
assert_eq!(bonds[uid as usize][server], I32F32::from_num(7_489));
717717
// Note B_ij = floor(1 / 64 * 65_535) / 65_535 = 1023 / 65_535, then max-upscaled to 65_535
718718
}
719719
for uid in servers {
@@ -1060,10 +1060,10 @@ fn test_bonds() {
10601060
P: [0.0499999989, 0.0999999992, 0.1500000006, 0.2000000011, 0.049998779, 0.1000006103, 0.1499963375, 0.2000042726]
10611061
emaB: [[(4, 0.2499999937), (5, 0.2499999953), (6, 0.2499999937), (7, 0.2499999937)], [(4, 0.4999999942), (5, 0.499999997), (6, 0.4999999942), (7, 0.4999999942)], [(4, 0.7499999937), (5, 0.7499999981), (6, 0.7499999995), (7, 0.7499999995)], [(4, 1), (5, 1), (6, 1), (7, 1)], [], [], [], []] */
10621062
let bonds = SubtensorModule::get_bonds( netuid );
1063-
assert_eq!(bonds[0][4], 16383);
1064-
assert_eq!(bonds[1][4], 32767);
1065-
assert_eq!(bonds[2][4], 49151);
1066-
assert_eq!(bonds[3][4], 65535);
1063+
assert_eq!(bonds[0][4], 2_147_430);
1064+
assert_eq!(bonds[1][4], 4_294_861);
1065+
assert_eq!(bonds[2][4], 6_442_293);
1066+
assert_eq!(bonds[3][4], 8_589_724);
10671067

10681068
// === Set self-weight only on val1
10691069
let uid = 0;
@@ -1107,10 +1107,10 @@ fn test_bonds() {
11071107
P: [0.0449983515, 0.1011105615, 0.1516672159, 0.2022238704, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726]
11081108
emaB: [[(4, 0.2225175085), (5, 0.2225175085), (6, 0.2225175085), (7, 0.2225175085)], [(4, 0.499993208), (5, 0.4999932083), (6, 0.4999932083), (7, 0.4999932083)], [(4, 0.7499966028), (5, 0.7499966032), (6, 0.7499966032), (7, 0.7499966032)], [(4, 1), (5, 1), (6, 1), (7, 1)], [], [], [], []] */
11091109
let bonds = SubtensorModule::get_bonds( netuid );
1110-
assert_eq!(bonds[0][4], 14582);
1111-
assert_eq!(bonds[1][4], 32767);
1112-
assert_eq!(bonds[2][4], 49151);
1113-
assert_eq!(bonds[3][4], 65535);
1110+
assert_eq!(bonds[0][4], 0);
1111+
assert_eq!(bonds[1][4], 42_948_61);
1112+
assert_eq!(bonds[2][4], 6_442_293);
1113+
assert_eq!(bonds[3][4], 8_589_724);
11141114

11151115
// === Set self-weight only on val2
11161116
let uid = 1;
@@ -1143,10 +1143,10 @@ fn test_bonds() {
11431143
P: [0.040496806, 0.0909997837, 0.157929636, 0.2105737738, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726]
11441144
emaB: [[(4, 0.192316476), (5, 0.192316476), (6, 0.192316476), (7, 0.192316476)], [(4, 0.4321515555), (5, 0.4321515558), (6, 0.4321515558), (7, 0.4321515558)], [(4, 0.7499967015), (5, 0.7499967027), (6, 0.7499967027), (7, 0.7499967027)], [(4, 1), (5, 1), (6, 1), (7, 1)], [], [], [], []] */
11451145
let bonds = SubtensorModule::get_bonds( netuid );
1146-
assert_eq!(bonds[0][4], 12603);
1147-
assert_eq!(bonds[1][4], 28321);
1148-
assert_eq!(bonds[2][4], 49151);
1149-
assert_eq!(bonds[3][4], 65535);
1146+
assert_eq!(bonds[0][4], 0);
1147+
assert_eq!(bonds[1][4], 0);
1148+
assert_eq!(bonds[2][4], 6_442_293);
1149+
assert_eq!(bonds[3][4], 8_589_724);
11501150

11511151
// === Set self-weight only on val3
11521152
let uid = 2;
@@ -1179,10 +1179,10 @@ fn test_bonds() {
11791179
P: [0.0999999999, 0.2, 0.2999999998, 0.4, 0, 0, 0, 0]
11801180
emaB: [[(4, 0.1923094518), (5, 0.1923094518), (6, 0.1923094518), (7, 0.1923094518)], [(4, 0.4321507583), (5, 0.4321507583), (6, 0.4321507583), (7, 0.4321507583)], [(4, 0.7499961846), (5, 0.7499961846), (6, 0.7499961846), (7, 0.7499961846)], [(4, 1), (5, 1), (6, 1), (7, 1)], [], [], [], []] */
11811181
let bonds = SubtensorModule::get_bonds( netuid );
1182-
assert_eq!(bonds[0][7], 12602);
1183-
assert_eq!(bonds[1][7], 28320);
1184-
assert_eq!(bonds[2][7], 49150);
1185-
assert_eq!(bonds[3][7], 65535);
1182+
assert_eq!(bonds[0][7], 0);
1183+
assert_eq!(bonds[1][7], 0);
1184+
assert_eq!(bonds[2][7], 0);
1185+
assert_eq!(bonds[3][7], 0);
11861186

11871187
// === Set val3->srv4: 1
11881188
assert_ok!(SubtensorModule::set_weights(RuntimeOrigin::signed(U256::from(2)), netuid, vec![7], vec![u16::MAX], 0));
@@ -1214,10 +1214,10 @@ fn test_bonds() {
12141214
P: [0.0364437331, 0.081898629, 0.1635654932, 0.2180921442, 0, 0, 0, 0.5]
12151215
emaB: [[(4, 0.1922941932), (5, 0.1922941932), (6, 0.1922941932), (7, 0.1671024568)], [(4, 0.4321354993), (5, 0.4321354993), (6, 0.4321354993), (7, 0.3755230587)], [(4, 0.7499809256), (5, 0.7499809256), (6, 0.7499809256), (7, 0.749983425)], [(4, 1), (5, 1), (6, 1), (7, 1)], [], [], [], []] */
12161216
let bonds = SubtensorModule::get_bonds( netuid );
1217-
assert_eq!(bonds[0][7], 10951);
1218-
assert_eq!(bonds[1][7], 24609);
1219-
assert_eq!(bonds[2][7], 49150);
1220-
assert_eq!(bonds[3][7], 65535);
1217+
assert_eq!(bonds[0][7], 0);
1218+
assert_eq!(bonds[1][7], 0);
1219+
assert_eq!(bonds[2][7], 25_770_353);
1220+
assert_eq!(bonds[3][7], 34_360_471);
12211221

12221222
next_block();
12231223
if sparse { SubtensorModule::epoch( netuid, 1_000_000_000 ); }
@@ -1235,10 +1235,10 @@ fn test_bonds() {
12351235
P: [0.0327994274, 0.0737066122, 0.1686381293, 0.2248558307, 0, 0, 0, 0.5]
12361236
emaB: [[(4, 0.1922789337), (5, 0.1922789337), (6, 0.1922789337), (7, 0.1458686984)], [(4, 0.4321202405), (5, 0.4321202405), (6, 0.4321202405), (7, 0.3277949789)], [(4, 0.749965667), (5, 0.749965667), (6, 0.749965667), (7, 0.74998335)], [(4, 1), (5, 1), (6, 1), (7, 1)], [], [], [], []] */
12371237
let bonds = SubtensorModule::get_bonds( netuid );
1238-
assert_eq!(bonds[0][7], 9559);
1239-
assert_eq!(bonds[1][7], 21482);
1240-
assert_eq!(bonds[2][7], 49150);
1241-
assert_eq!(bonds[3][7], 65535);
1238+
assert_eq!(bonds[0][7], 0);
1239+
assert_eq!(bonds[1][7], 0);
1240+
assert_eq!(bonds[2][7], 25_770_353);
1241+
assert_eq!(bonds[3][7], 34_360_471);
12421242

12431243
next_block();
12441244
if sparse { SubtensorModule::epoch( netuid, 1_000_000_000 ); }
@@ -1256,10 +1256,10 @@ fn test_bonds() {
12561256
P: [0.029518068, 0.0663361375, 0.1732031347, 0.2309426593, 0, 0, 0, 0.5]
12571257
emaB: [[(4, 0.192263675), (5, 0.192263675), (6, 0.192263675), (7, 0.1278155716)], [(4, 0.4321049813), (5, 0.4321049813), (6, 0.4321049813), (7, 0.2872407278)], [(4, 0.7499504078), (5, 0.7499504078), (6, 0.7499504078), (7, 0.7499832863)], [(4, 1), (5, 1), (6, 1), (7, 1)], [], [], [], []] */
12581258
let bonds = SubtensorModule::get_bonds( netuid );
1259-
assert_eq!(bonds[0][7], 8376);
1260-
assert_eq!(bonds[1][7], 18824);
1261-
assert_eq!(bonds[2][7], 49150);
1262-
assert_eq!(bonds[3][7], 65535);
1259+
assert_eq!(bonds[0][7], 0);
1260+
assert_eq!(bonds[1][7], 0);
1261+
assert_eq!(bonds[2][7], 25_770_353);
1262+
assert_eq!(bonds[3][7], 34_360_471);
12631263

12641264
next_block();
12651265
if sparse { SubtensorModule::epoch( netuid, 1_000_000_000 ); }
@@ -1401,12 +1401,12 @@ fn test_bonds_with_liquid_alpha() {
14011401
// Active stake: [1, 2, 3, 4]
14021402
// ΔB = W◦S = [0.25*1, 0.5*2, 0.75*3, 1.0*4] = [0.25, 1.0, 2.25, 4.0]
14031403
// Normalize ΔB: [0.25/7.5, 1.0/7.5, 2.25/7.5, 4.0/7.5] = [0.0333, 0.1333, 0.3, 0.5333]
1404-
// Final bonds for netuid: [16383, 32767, 49151, 65535]
1404+
// Final bonds for netuid: [530, 1_061, 1_591, 2_122]
14051405

1406-
assert_eq!(bonds[0][4], 16383); // Note: Calculated as explained above
1407-
assert_eq!(bonds[1][4], 32767); // Note: Calculated as explained above
1408-
assert_eq!(bonds[2][4], 49151); // Note: Calculated as explained above
1409-
assert_eq!(bonds[3][4], 65535); // Note: Calculated as explained above
1406+
assert_eq!(bonds[0][4], 17_385_264); // Note: Calculated as explained above
1407+
assert_eq!(bonds[1][4], 34_770_528); // Note: Calculated as explained above
1408+
assert_eq!(bonds[2][4], 52_155_793); // Note: Calculated as explained above
1409+
assert_eq!(bonds[3][4], 69_541_058); // Note: Calculated as explained above
14101410

14111411
// === Set self-weight only on val1
14121412
let uid = 0;
@@ -1425,10 +1425,10 @@ fn test_bonds_with_liquid_alpha() {
14251425
}
14261426

14271427
let bonds = SubtensorModule::get_bonds(netuid);
1428-
assert_eq!(bonds[0][4], 2862);
1429-
assert_eq!(bonds[1][4], 32767);
1430-
assert_eq!(bonds[2][4], 49151);
1431-
assert_eq!(bonds[3][4], 65535);
1428+
assert_eq!(bonds[0][4], 0);
1429+
assert_eq!(bonds[1][4], 34_770_528);
1430+
assert_eq!(bonds[2][4], 52_155_793);
1431+
assert_eq!(bonds[3][4], 69_541_058);
14321432

14331433
// === Set self-weight only on val2
14341434
let uid = 1;
@@ -1488,10 +1488,10 @@ fn test_bonds_with_liquid_alpha() {
14881488
Pruning Scores: [0.0016997808, 0.0151777493, 0.2070524206, 0.2760700488, 0.049998779, 0.1000006103, 0.1499963377, 0.2000042726]
14891489
*/
14901490

1491-
assert_eq!(bonds[0][4], 435);
1492-
assert_eq!(bonds[1][4], 4985);
1493-
assert_eq!(bonds[2][4], 49151);
1494-
assert_eq!(bonds[3][4], 65535);
1491+
assert_eq!(bonds[0][4], 0);
1492+
assert_eq!(bonds[1][4], 0);
1493+
assert_eq!(bonds[2][4], 52155793);
1494+
assert_eq!(bonds[3][4], 69_541_058);
14951495
});
14961496
}
14971497

@@ -1623,7 +1623,7 @@ fn test_active_stake() {
16231623
assert_eq!(*i, 0);
16241624
}
16251625
for i in bond.iter().take(n as usize).skip((n / 2) as usize) {
1626-
assert_eq!(*i, I32F32::from_num(65_535)); // floor(0.5*(2^16-1))/(2^16-1), then max-upscale to 65_535
1626+
assert_eq!(*i, I32F32::from_num(26_843_545)); // floor(0.5*(2^32-1))/(2^32-1)
16271627
}
16281628
}
16291629
let activity_cutoff: u64 = SubtensorModule::get_activity_cutoff(netuid) as u64;
@@ -1669,22 +1669,19 @@ fn test_active_stake() {
16691669
P: [0.275, 0.2249999999, 0.25, 0.25]
16701670
P (u16): [65535, 53619, 59577, 59577] */
16711671
let bonds = SubtensorModule::get_bonds(netuid);
1672-
assert_eq!(SubtensorModule::get_dividends_for_uid(netuid, 0), 36044); // Note D = floor((0.5 * 0.9 + 0.1) * 65_535)
1673-
assert_eq!(SubtensorModule::get_emission_for_uid(netuid, 0), 274999999); // Note E = 0.5 * 0.55 * 1_000_000_000 = 275_000_000 (discrepancy)
1672+
assert_eq!(SubtensorModule::get_dividends_for_uid(netuid, 0), 65_535); // Note D = floor((0.5 * 0.9 + 0.1) * 65_535)
1673+
assert_eq!(
1674+
SubtensorModule::get_emission_for_uid(netuid, 0),
1675+
500_000_000
1676+
); // Note E = 0.5 * 0.55 * 1_000_000_000 = 275_000_000 (discrepancy)
16741677
for server in ((n / 2) as usize)..n as usize {
1675-
assert_eq!(bonds[0][server], I32F32::from_num(65_535)); // floor(0.55*(2^16-1))/(2^16-1), then max-upscale
1678+
assert_eq!(bonds[0][server], I32F32::from_num(107_374_182)); // floor(0.55*(2^16-1))/(2^16-1), then max-upscale
16761679
}
16771680
for validator in 1..(n / 2) {
1678-
assert_eq!(
1679-
SubtensorModule::get_dividends_for_uid(netuid, validator),
1680-
29490
1681-
); // Note D = floor((0.5 * 0.9) * 65_535)
1682-
assert_eq!(
1683-
SubtensorModule::get_emission_for_uid(netuid, validator),
1684-
224999999
1685-
); // Note E = 0.5 * 0.45 * 1_000_000_000 = 225_000_000 (discrepancy)
1681+
assert_eq!(SubtensorModule::get_dividends_for_uid(netuid, validator), 0); // Note D = floor((0.5 * 0.9) * 65_535)
1682+
assert_eq!(SubtensorModule::get_emission_for_uid(netuid, validator), 0); // Note E = 0.5 * 0.45 * 1_000_000_000 = 225_000_000 (discrepancy)
16861683
for server in ((n / 2) as usize)..n as usize {
1687-
assert_eq!(bonds[validator as usize][server], I32F32::from_num(53619));
1684+
assert_eq!(bonds[validator as usize][server], I32F32::from_num(0));
16881685
// floor(0.45*(2^16-1))/(2^16-1), then max-upscale
16891686
}
16901687
}
@@ -1730,15 +1727,21 @@ fn test_active_stake() {
17301727
P: [0.272501133, 0.2274988669, 0.25, 0.25]
17311728
P (u16): [65535, 54711, 60123, 60123] */
17321729
let bonds = SubtensorModule::get_bonds(netuid);
1733-
assert_eq!(SubtensorModule::get_dividends_for_uid(netuid, 0), 35716); // Note D = floor((0.55 * 0.9 + 0.5 * 0.1) * 65_535)
1734-
assert_eq!(SubtensorModule::get_emission_for_uid(netuid, 0), 272501132); // Note E = 0.5 * (0.55 * 0.9 + 0.5 * 0.1) * 1_000_000_000 = 272_500_000 (discrepancy)
1730+
assert_eq!(SubtensorModule::get_dividends_for_uid(netuid, 0), 32_767); // Note D = floor((0.55 * 0.9 + 0.5 * 0.1) * 65_535)
1731+
assert_eq!(
1732+
SubtensorModule::get_emission_for_uid(netuid, 0),
1733+
250_000_000
1734+
); // Note E = 0.5 * (0.55 * 0.9 + 0.5 * 0.1) * 1_000_000_000 = 272_500_000 (discrepancy)
17351735
for server in ((n / 2) as usize)..n as usize {
1736-
assert_eq!(bonds[0][server], I32F32::from_num(65_535)); // floor((0.55 * 0.9 + 0.5 * 0.1)*(2^16-1))/(2^16-1), then max-upscale
1736+
assert_eq!(bonds[0][server], I32F32::from_num(53_687_090)); // floor((0.55 * 0.9 + 0.5 * 0.1)*(2^16-1))/(2^16-1), then max-upscale
17371737
}
1738-
assert_eq!(SubtensorModule::get_dividends_for_uid(netuid, 1), 29818); // Note D = floor((0.45 * 0.9 + 0.5 * 0.1) * 65_535)
1739-
assert_eq!(SubtensorModule::get_emission_for_uid(netuid, 1), 227498866); // Note E = 0.5 * (0.45 * 0.9 + 0.5 * 0.1) * 1_000_000_000 = 227_500_000 (discrepancy)
1738+
assert_eq!(SubtensorModule::get_dividends_for_uid(netuid, 1), 32_767); // Note D = floor((0.45 * 0.9 + 0.5 * 0.1) * 65_535)
1739+
assert_eq!(
1740+
SubtensorModule::get_emission_for_uid(netuid, 1),
1741+
250_000_000
1742+
); // Note E = 0.5 * (0.45 * 0.9 + 0.5 * 0.1) * 1_000_000_000 = 227_500_000 (discrepancy)
17401743
for server in ((n / 2) as usize)..n as usize {
1741-
assert_eq!(bonds[1][server], I32F32::from_num(54712)); // floor((0.45 * 0.9 + 0.5 * 0.1)/(0.55 * 0.9 + 0.5 * 0.1)*(2^16-1))
1744+
assert_eq!(bonds[1][server], I32F32::from_num(53_687_090)); // floor((0.45 * 0.9 + 0.5 * 0.1)/(0.55 * 0.9 + 0.5 * 0.1)*(2^16-1))
17421745
}
17431746
});
17441747
}
@@ -1925,8 +1928,8 @@ fn test_outdated_weights() {
19251928
let bonds = SubtensorModule::get_bonds(netuid);
19261929
assert_eq!(SubtensorModule::get_dividends_for_uid(netuid, 0), 32767); // Note D = floor(0.5 * 65_535)
19271930
assert_eq!(SubtensorModule::get_emission_for_uid(netuid, 0), 250000000); // Note E = 0.5 * 0.5 * 1_000_000_000 = 249311245
1928-
assert_eq!(bonds[0][2], I32F32::from_num(65_535)); // floor(0.5*(2^16-1))/(2^16-1), then max-upscale
1929-
assert_eq!(bonds[0][3], I32F32::from_num(65_535)); // only uid0 has updated weights for new reg
1931+
assert_eq!(bonds[0][2], I32F32::from_num(47_721_615)); // floor(0.5*(2^16-1))/(2^16-1), then max-upscale
1932+
assert_eq!(bonds[0][3], I32F32::from_num(0)); // only uid0 has updated weights for new reg
19301933
});
19311934
}
19321935

0 commit comments

Comments
 (0)