(capacity: int, number_of_tasks: int, wait: float = 0.5)
| 32 | await asyncio.gather(*[ask_the_question(wait) for _ in range(n)]) |
| 33 | |
| 34 | async def verify_asyncify(capacity: int, number_of_tasks: int, wait: float = 0.5): |
| 35 | with dspy.context(async_max_workers=capacity): |
| 36 | start = time() |
| 37 | await run_n_tasks(number_of_tasks, wait) |
| 38 | end = time() |
| 39 | total_time = end - start |
| 40 | |
| 41 | # If asyncify is working correctly, the total time should be less than the total number of loops |
| 42 | # `(number_of_tasks / capacity)` times wait time, plus the computational overhead. The lower bound should |
| 43 | # be `math.floor(number_of_tasks * 1.0 / capacity) * wait` because there are more than |
| 44 | # `math.floor(number_of_tasks * 1.0 / capacity)` loops. |
| 45 | lower_bound = math.floor(number_of_tasks * 1.0 / capacity) * wait |
| 46 | upper_bound = math.ceil(number_of_tasks * 1.0 / capacity) * wait + 2 * wait # 2*wait for buffer |
| 47 | |
| 48 | assert lower_bound < total_time < upper_bound |
| 49 | |
| 50 | await verify_asyncify(4, 10) |
| 51 | await verify_asyncify(8, 15) |
no test coverage detected
searching dependent graphs…