I am new to this library and trying out some stuff. I have an approximation function, which runs loop for say 10 times, each time there are a couple or more approximation functions inside the loop. I have even used bootstrapping operation to reduce the noise. Somewhere while running the loop, I get the following error

RuntimeError: /openfhe-development/src/core/include/lattice/hal/default/dcrtpoly-impl.h:l.695:DropLastElement(): DropLastElement: Removing last element of DCRTPoly renders it invalid.

What might be the error reason and how should I resolve it?

Is there some way to compute the noise budget, like say at a position if I can find that there are only 2 more multiplications possible, but there are more multiplications required ahead then I should perform bootstrap?

You can print out ctxt->GetLevel(), the ciphertext level starts at 0 upon fresh encryption and gets incremented (internally) by 1 as you multiply. When it is close to the multiplicative depth, you should refresh the ciphertext using bootstrapping.

Okay, thank you, I will try that. Also, for a use case, when decrypting I get an error

RuntimeError: /openfhe-development/src/pke/lib/encoding/ckkspackedencoding.cpp:l.535:Decode(): The decryption failed because the approximation error is too high. Check the parameters.

Most likely, this is caused by setting the multiplicative depth in the cryptocontext smaller than required by the computation. Try estimating the multiplicative depth of the computation you are performing (including the levels required for bootstrapping) and set that value.