@@ -15,6 +15,9 @@ void expect_tree_matches_normal_reference_sample_of(const ReferenceSampleTree &t
1515 }
1616 auto expected = TableauSimulator<MAX_BITWORD_WIDTH>::reference_sample_circuit (circuit);
1717 EXPECT_EQ (actual, expected);
18+ for (size_t index = 0 ; index < decompressed.size (); ++index) {
19+ ASSERT_EQ (tree[index], decompressed[index]) << " index: " << index;
20+ }
1821}
1922
2023TEST (ReferenceSampleTree, equality) {
@@ -102,20 +105,24 @@ TEST(ReferenceSampleTree, simplified) {
102105
103106TEST (ReferenceSampleTree, decompress_into) {
104107 std::vector<bool > result;
105- ReferenceSampleTree{
108+ ReferenceSampleTree tree_under_test {
106109 .prefix_bits = {1 , 1 , 0 , 1 },
107110 .suffix_children = {ReferenceSampleTree{
108111 .prefix_bits = {1 },
109112 .suffix_children = {},
110113 .repetitions = 5 ,
111114 }},
112115 .repetitions = 2 ,
116+ };
117+ tree_under_test.decompress_into (result);
118+ std::vector<bool > expected = std::vector<bool >{1 , 1 , 0 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 1 , 1 , 1 , 1 , 1 , 1 };
119+ ASSERT_EQ (result, expected);
120+ for (size_t index = 0 ; index < expected.size (); ++index) {
121+ ASSERT_EQ (tree_under_test[index], expected[index]) << " index: " << index;
113122 }
114- .decompress_into (result);
115- ASSERT_EQ (result, (std::vector<bool >{1 , 1 , 0 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 1 , 1 , 1 , 1 , 1 , 1 }));
116123
117124 result.clear ();
118- ReferenceSampleTree{
125+ tree_under_test = ReferenceSampleTree{
119126 .prefix_bits = {1 , 1 , 0 , 1 },
120127 .suffix_children =
121128 {
@@ -131,10 +138,14 @@ TEST(ReferenceSampleTree, decompress_into) {
131138 },
132139 },
133140 .repetitions = 1 ,
141+ };
142+ tree_under_test.decompress_into (result);
143+ expected =
144+ std::vector<bool >{1 , 1 , 0 , 1 , 1 , 0 , 1 , 1 , 0 , 1 , 1 , 0 , 1 , 1 , 0 , 1 , 1 , 0 , 1 , 1 , 0 , 1 , 1 , 0 , 1 , 1 , 0 , 1 , 0 , 0 };
145+ ASSERT_EQ (result, expected);
146+ for (size_t index = 0 ; index < expected.size (); ++index) {
147+ ASSERT_EQ (tree_under_test[index], expected[index]) << " index: " << index;
134148 }
135- .decompress_into (result);
136- ASSERT_EQ (result, (std::vector<bool >{1 , 1 , 0 , 1 , 1 , 0 , 1 , 1 , 0 , 1 , 1 , 0 , 1 , 1 , 0 ,
137- 1 , 1 , 0 , 1 , 1 , 0 , 1 , 1 , 0 , 1 , 1 , 0 , 1 , 0 , 0 }));
138149}
139150
140151TEST (ReferenceSampleTree, simple_circuit) {
@@ -292,3 +303,54 @@ TEST(ReferenceSampleTree, surface_code_with_pauli_vs_normal_reference_sample) {
292303 ASSERT_EQ (ref.size (), circuit.count_measurements ());
293304 expect_tree_matches_normal_reference_sample_of (ref, circuit);
294305}
306+
307+ TEST (ReferenceSampleTree, random_access_large_tree) {
308+ ReferenceSampleTree tree_under_test{
309+ .prefix_bits = {1 , 1 , 0 , 1 },
310+ .suffix_children =
311+ {ReferenceSampleTree{
312+ .prefix_bits = {1 , 0 , 1 },
313+ .suffix_children = {},
314+ .repetitions = 60'000'000 ,
315+ },
316+ ReferenceSampleTree{
317+ .prefix_bits = {0 , 0 , 0 , 0 , 0 , 0 , 1 },
318+ .suffix_children = {ReferenceSampleTree{
319+ .prefix_bits = {1 , 1 , 1 , 0 , 0 , 1 },
320+ .suffix_children = {},
321+ .repetitions = 42 ,
322+ }},
323+ .repetitions = 2'000'000'000 ,
324+ },
325+ ReferenceSampleTree{
326+ .prefix_bits = {0 , 0 , 0 , 0 , 1 },
327+ .suffix_children = {},
328+ .repetitions = 999'000'000 ,
329+ }},
330+ .repetitions = 1'234'000 ,
331+ };
332+
333+ std::vector<bool > expected_beginning = std::vector<bool >{1 , 1 , 0 , 1 , 1 , 0 , 1 , 1 , 0 , 1 , 1 , 0 , 1 , 1 , 0 , 1 };
334+ for (size_t index = 0 ; index < expected_beginning.size (); ++index) {
335+ ASSERT_EQ (tree_under_test[index], expected_beginning[index]) << " index: " << index;
336+ }
337+
338+ uint64_t whole_tree_size = tree_under_test.size ();
339+ ASSERT_EQ (
340+ whole_tree_size,
341+ 1'234'000ULL * (4 + (60'000'000ULL * 3 ) + (2'000'000'000ULL * (7 + (42 * 6 ))) + (999'000'000ULL * 5 )));
342+
343+ std::vector<bool > expected_ending =
344+ std::vector<bool >{0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 1 };
345+ for (uint64_t index = 0 ; index < expected_ending.size (); ++index) {
346+ ASSERT_EQ (tree_under_test[whole_tree_size - expected_ending.size () + index], expected_ending[index])
347+ << " index: " << index;
348+ }
349+ // Same thing on previous outer iteration.
350+ uint64_t one_outer_iter_before_ending = whole_tree_size - (whole_tree_size / 1'234'000ULL );
351+ for (uint64_t index = 0 ; index < expected_ending.size (); ++index) {
352+ ASSERT_EQ (
353+ tree_under_test[one_outer_iter_before_ending - expected_ending.size () + index], expected_ending[index])
354+ << " index: " << index;
355+ }
356+ }
0 commit comments