
In this article, we'll explore the Python library Numba and see how it can significantly improve the performance of Python code using parallel execution and CUDA acceleration.
To achieve this, we'll use a problem that is both well-suited for parallel computing and easy to visualize: heatmap generation.
In any mapping system, a map is represented as a collection of small pieces called tiles. Typically, the base map is rendered first (which is outside the scope of this article), and then an additional layer — such as a heatmap — is drawn on top of it.
The unofficial Perekrestok website is a third-party resource. If its HTML structure changes, the parser will stop working. Therefore, treat it as an example or template rather than a reliable production-ready solution. The screenshot below shows the website as it appeared at the time this article was written.
We will consider a store to be accessible if it is located within 1.2 km of the point being evaluated. This distance corresponds to approximately a 15-minute walk.
As the subject of our experiment, we'll use the Perekrestok supermarket chain in Moscow and visualize the accessibility of its stores across the city.
In production environments, tiles are typically pre-generated and then served by a tile server. However, since the focus of this article is on accelerating computations, we'll generate them on the fly. The faster the tiles are generated, the smoother the map rendering will be.
Using the aiohttp library, we'll download the page and then use BeautifulSoup to extract the store addresses from it:
async def get_shops_addresses(session):
async with session.get('https://perekrestok-promo.ru/store/g-moskva') as response:
html = await response.text()
tree = BeautifulSoup(html, 'html.parser')
feature = 'Магазин Перекресток по адресу '
raw_links = tree.body.find_all('a', string=re.compile(feature))
links = [(link.text.replace(feature, '')) for link in raw_links]
return linksIn the previous step, we obtained a list of store addresses. Now we'll use the Google Geocoding API to convert each address into geographic coordinates: