Walk When the Speed Drops
Here is a simple general observation: the steeper the slope, the slower your speed, to the point where it gets close to walking speed. At this point, you'll notice that your pace is not much faster than your walking speed. In this case, it would be much better to walk at a fast pace given the benefits that you will reap: lower heart rate, improved oxygenation and less energy expenditure.
Naturally, each runner will look at their abilities and experience in tackling a steep path to assess their own limits according to the race profile (distance, number of hills, gradient, total elevation gain, etc.) In any case, it's up to you to decide when it would be better to manage your ascent by walking quickly rather than running uphill.
Adapting the Pace to the Heart Rate
When faced with a less steep yet particularly long slope, you can also adapt your pace to your heart rate to find out when it would be better to walk rather than run. You can even define your upper heart rate zone with the help of an alarm notification that you can set on your heart rate monitor watch: as soon as you enter the upper zone, walk until the end of the climb and gradually speed up again on the subsequent flat or downhill sections.
By monitoring your heart rate, you can manage the level of effort you make when you run. This is a particularly useful for beginner runners. Indeed, it helps them to not go too fast and get in difficulty, and plays a significant role in achieving success when running longer distances or starting to run in nature.
With experience, you will instinctively know when it's time to slow down in order to make up time later!