def optimization_one_iteration(optimizer, instance_var, prompt, tests):
    """
    This is a single iteration of optimization
    :param optimizer:
    :param instance_var:
    :param prompt:
    :return:
    """
    pt = PythonEvaluator()
    tests = tests.split("\n")

    # Evaluate the code
    # state is True/False for each test
    state, test_string = pt.evaluate(instance_var.value, tests)

    optimizer.zero_grad()
    loss_fn = CodeTestTimewithTests(engine=ENGINE_API)

    test_time_loss = loss_fn(prompt, instance_var, test_string)

    test_time_loss.backward()
    optimizer.step()

    return state, test_string

    This is a single iteration of optimization
    :param optimizer:
    :param instance_var:
    :param prompt:
    :return:
    
evaluation/code_optimization/leetcode_testtime_with_supervision.py