Skip to content

Conversation

@mpharrigan
Copy link
Collaborator

Not all bloq examples support tensor simulation. This report card automatically determines which bloq examples should be tensor simulable.

  • State vector simulation uses $2^n$ numbers to simulate a quantum state. The tensor protocol uses quimb to try to find more efficient contraction orderings. Quimb reports the contraction width, which is the minimum size of any intermediate tensor encountered in the contraciton. The simulation uses $2^w$ numbers, where $w$ is the width. We consider a width under 25 qubits as simulable.
  • Qualtran requires "flattening" out the bloq to turn it into an efficient tensor network. This may take too much time itself for large algorithms with many levels of abstraction. If the process of turning a bloq into a quimb tensor network and finding a contraction ordering takes longer than 8 seconds, we don't consider the bloq simulable.
  • The flattened structure needs to have explicit tensors. For bloqs with symbolic parameters, we either can't decompose & flatten them, or the tensors would be symbolic, which we don't support.

@mpharrigan
Copy link
Collaborator Author

Number of bloq examples considered

print(len(df))
304

Number of bloq examples successfully flattened

print(len(df[df['flat_dur'] > 0]))
263

Number of bloq examples with tensors

print(len(df[df['width'] > 0]))
157

Bloqs that are tensor simulable

print(len(df[df['width'] <= 25]))
df[df['width'] <= 25]
120
name cls flat_dur err tn_dur width width_dur
1 add_k_small AddK 0.026146 NaN 0.003073 8.0 0.003242
4 add_oop_small OutOfPlaceAdder 0.027389 NaN 0.003113 21.0 0.003324
8 add_small Add 0.023498 NaN 0.002645 16.0 0.002721
10 bitwise_not BitwiseNot 0.001586 NaN 0.000363 8.0 0.000347
12 xor Xor 0.006454 NaN 0.000576 16.0 0.000651
... ... ... ... ... ... ... ...
289 sparse_state_prep_via_rotations SparseStatePreparationViaRotations 1.489863 NaN 0.044312 12.0 0.039386
294 state_prep_alias StatePreparationAliasSampling 0.178420 NaN 0.010980 22.0 0.012333
296 state_prep_via_rotation StatePreparationViaRotations 0.311990 NaN 0.014321 12.0 0.009816
297 approx_cswap_small CSwapApprox 0.037106 NaN 0.003697 18.0 0.003618
300 swz_small SwapWithZero 0.019082 NaN 0.002103 14.0 0.001731

120 rows × 7 columns

Bloqs whose tensor network is too big

df[df['width'] > 25].sort_values(by='width')
name cls flat_dur err tn_dur width width_dur
20 leq LessThanEqual 0.173596 NaN 0.014591 2.600000e+01 0.017194
153 cplx_givens ComplexGivensRotationByPhaseGradient 0.135327 NaN 0.010783 2.800000e+01 0.012214
51 comparator Comparator 0.454121 NaN 0.023943 2.900000e+01 0.025806
299 multiplexed_cswap MultiplexedCSwap 0.116693 NaN 0.008720 3.000000e+01 0.008778
258 prepare_identity PrepareIdentity 0.001847 NaN 0.000339 3.000000e+01 0.000447
234 kaiser_window_state_small KaiserWindowState 0.000314 NaN 0.180226 3.200000e+01 0.000075
291 sparse_state_prep_alias_from_list SparseStatePreparationAliasSampling 0.309500 NaN 0.057082 3.400000e+01 0.024256
290 sparse_state_prep_alias SparseStatePreparationAliasSampling 0.244710 NaN 0.013807 3.400000e+01 0.014747
25 ctrl_add_or_sub_signed ControlledAddOrSubtract 0.076607 NaN 0.009669 3.400000e+01 0.009102
27 ctrl_add_or_sub_unsigned ControlledAddOrSubtract 0.080349 NaN 0.007428 3.400000e+01 0.008773
105 scaled_chebyshev_poly_odd ScaledChebyshevPolynomial 2.744674 NaN 0.121746 3.600000e+01 0.059081
233 black_box_select BlackBoxSelect 0.267093 NaN 0.019364 3.700000e+01 0.020489
56 sub_diff_size_regs Subtract 0.265051 NaN 0.033848 4.000000e+01 0.047651
184 qrom_multi_dim QROM 0.127911 NaN 0.010900 4.000000e+01 0.012139
2 add_diff_size_regs Add 0.125302 NaN 0.010692 4.000000e+01 0.016339
55 parallel_compare ParallelComparators 0.631275 NaN 0.025924 4.500000e+01 0.028546
212 ctrl_on_multiple_values CtrlSpecAnd 0.077075 NaN 0.008729 4.700000e+01 0.009076
302 swz_multi_dimensional SwapWithZero 0.440719 NaN 0.021182 5.600000e+01 0.020162
108 select_block SelectBlockEncoding 1.075520 NaN 0.107634 6.200000e+01 0.048434
104 black_box_select_block SelectBlockEncoding 0.860905 NaN 0.110791 6.200000e+01 0.049564
182 qroam_clean_multi_dim QROAMClean 2.641734 NaN 0.093979 6.300000e+01 0.079423
224 moddbl_large ModDbl 2.568159 NaN 0.070820 6.400000e+01 0.088628
127 cast Cast 0.000413 NaN 0.000515 6.400000e+01 0.000750
208 controlled_via_and_ints ControlledViaAnd 0.284635 NaN 0.022803 6.600000e+01 0.024899
188 qroam_multi_dim SelectSwapQROM 1.952651 NaN 0.061592 6.800000e+01 0.086867
140 sel_hubb SelectHubbard 2.580288 NaN 0.160665 8.800000e+01 0.184910
130 partition Partition 0.000736 NaN 0.000838 9.800000e+01 0.001213
3 add_k_large AddK 2.457865 NaN 0.059918 1.280000e+02 0.074924
61 sub_large Subtract 2.606371 NaN 0.070517 2.560000e+02 0.090522
59 sub_from_large SubtractFrom 2.378148 NaN 0.061737 2.560000e+02 0.072526
6 add_large Add 1.964227 NaN 0.051067 2.560000e+02 0.063128
83 cswap_large CSwap 1.041534 NaN 0.041354 2.580000e+02 0.122483
301 approx_cswap_large CSwapApprox 3.643124 NaN 0.056535 2.580000e+02 0.065362
5 add_oop_large OutOfPlaceAdder 1.619623 NaN 0.046654 3.210000e+02 0.057121
36 plus_equal_product PlusEqualProduct 0.000766 NaN 0.002239 6.553600e+04 0.000107
265 add_into_phase_grad AddIntoPhaseGrad 0.000497 NaN 0.004727 6.553600e+04 0.000104
39 square Square 0.000426 NaN 0.001193 4.294967e+09 0.000140

Bloqs without tensors

Due to errors encountered in flattening or if the bloq's callees don't support tensor simulation.

df[df['width'].isna()]
name cls flat_dur err tn_dur width width_dur
0 add_k AddK 0.016689 AddK does not support tensor simulation. NaN NaN NaN
7 add_oop_symb OutOfPlaceAdder 0.017955 OutOfPlaceAdder does not support tensor simula... NaN NaN NaN
9 add_symb Add 0.018177 Add does not support tensor simulation. NaN NaN NaN
11 bitwise_not_symb BitwiseNot 0.016773 XGate⨂n does not support tensor simulation. NaN NaN NaN
13 xor_symb Xor 0.021624 Xor does not support tensor simulation. NaN NaN NaN
... ... ... ... ... ... ... ...
292 sparse_state_prep_alias_symb SparseStatePreparationAliasSampling 0.005134 PrepareUniformSuperposition does not support t... NaN NaN NaN
293 state_prep_alias_symb StatePreparationAliasSampling 0.018301 PrepareUniformSuperposition does not support t... NaN NaN NaN
295 state_prep_via_rotation_symb StatePreparationViaRotations NaN Split cannot have a symbolic data type. NaN NaN NaN
298 approx_cswap_symb CSwapApprox 0.016267 CSwapApprox does not support tensor simulation. NaN NaN NaN
303 swz SwapWithZero NaN Timeout NaN NaN NaN

147 rows × 7 columns

Slowest to flatten

Within the overall timeout

df.sort_values(by='flat_dur', ascending=False).head()
name cls flat_dur err tn_dur width width_dur
107 black_box_lcu_block LCUBlockEncoding 4.766397 ModAddK does not support tensor simulation. NaN NaN NaN
301 approx_cswap_large CSwapApprox 3.643124 NaN 0.056535 258.0 0.065362
105 scaled_chebyshev_poly_odd ScaledChebyshevPolynomial 2.744674 NaN 0.121746 36.0 0.059081
182 qroam_clean_multi_dim QROAMClean 2.641734 NaN 0.093979 63.0 0.079423
61 sub_large Subtract 2.606371 NaN 0.070517 256.0 0.090522

Flattening is the rate-limiting step.

For bloqs that have been successfully flattened, the maximum tensor-network-construction and tensor-contraction-ordering durations are less than 0.5s. Note: the contraction finding code uses the fast, naive approach. One can choose more expensive approaches where the contraciton-ordering-finding is more expensive.

# Slowest tn_dur
df.sort_values(by='tn_dur', ascending=False).head()
name cls flat_dur err tn_dur width width_dur
234 kaiser_window_state_small KaiserWindowState 0.000314 NaN 0.180226 32.0 0.000075
140 sel_hubb SelectHubbard 2.580288 NaN 0.160665 88.0 0.184910
105 scaled_chebyshev_poly_odd ScaledChebyshevPolynomial 2.744674 NaN 0.121746 36.0 0.059081
104 black_box_select_block SelectBlockEncoding 0.860905 NaN 0.110791 62.0 0.049564
108 select_block SelectBlockEncoding 1.075520 NaN 0.107634 62.0 0.048434
# Slowest width_dur
df.sort_values(by='width_dur', ascending=False).head()
name cls flat_dur err tn_dur width width_dur
140 sel_hubb SelectHubbard 2.580288 NaN 0.160665 88.0 0.184910
83 cswap_large CSwap 1.041534 NaN 0.041354 258.0 0.122483
49 sparse_permutation Permutation 0.881599 NaN 0.031373 12.0 0.105166
16 clineardepthgreaterthan_example CLinearDepthGreaterThan 0.224516 NaN 0.011326 24.0 0.098919
103 chebyshev_poly_even ChebyshevPolynomial 0.978074 NaN 0.027787 15.0 0.092611

@tanujkhattar tanujkhattar merged commit 246e5d3 into quantumlib:main Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants