The spark should ignite the fuel-air mixture during the compression stroke in such a way that the real increase of pressure occurs after TDC and knocking is avoided.
The spark plug is positioned as much as possible in the hottest spot in the combustion chamber and/or the gas flow is controlled such that the ignitable mixture develops there. This takes place at weight ratios (air: fuel petrol) between 10:1 and 17:1. The ignition is triggered almost exclusively electronically according to the working operation. Either it is compressed so low that the fuel-air mixture does not inflame itself, or a knock sensor is included in the regulation.
The externally supplied ignition is typical for the petrol engine. The picture shows ignition experiments with a glass cylinder, where a chip learns from a given combustion chamber pressure, to optimize the ignition point.