Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a fix to ensure remote folder is created before running batch o… #2007

Merged
merged 1 commit into from
Oct 9, 2024

Conversation

prashkh
Copy link
Contributor

@prashkh prashkh commented Oct 7, 2024

…f mode solver simulations.

One user reported that running batch solver for mode solver created multiple folders with the same name on our web platform. We figured out a way to fix this by creating the folder explicitly first before running the async call for batch solver. Last time I had asked the user to just implement in their frontend code and it works so we just need to include this before the next release. Thank you!

# Create the folder before running the parallel computation and wait one second before running the batch simulation job
folder = Folder.create(folder_name=folder_name)
import time
time.sleep(1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put from time import sleep at the top level of this file and use sleep(1) here.

But separately, @magiWei , is there a better way to wait to make sure that the folder is created? This seems too hacky.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current way to create a folder is https synchronous interaction, the interface will respond to success or failure. Therefore, getting the interface returned will let you know the interface created by the folder.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean there should be no need for a time.sleep() even in the current code? @prashkh do you know why you had to add it?

@prashkh
Copy link
Contributor Author

prashkh commented Oct 8, 2024

@momchil-flex if you don't explicitly add this, multiple folders with the same name is created on our web GUI and the batch simulations are randomly distributed across those folders with the same name (puzzling) when solving a batch of mode solver simulations.
The way I was able to fix this is by creating the folder explicitly first before running the async call for batch solver.

@momchil-flex
Copy link
Collaborator

So I can see why that would happen without the explicit folder create call, but I'm wondering why you still need to wait 1s. Generally it sounds like folder = Folder.create(folder_name=folder_name) should only return when the folder is created. Did you observe otherwise?

@prashkh
Copy link
Contributor Author

prashkh commented Oct 8, 2024

I don't remember testing with no delay. I can do that today. My assumption was that the run_batch already calls run and each run function creates a folder (ModeSolverTask.create(...)), if there is none. So, if there is no delay between explicitly creating the folder and running the batch simulation, it would again have the same problems. But I can definitely test this today. I used 1 sec delay just to be safe since in the run function I saw 0.5 sec delay being used.

    # Wait for task to finish
    prev_status = "draft"
    status = task.status
    while status not in ("success", "error", "diverged", "deleted"):
        if status != prev_status:
            log.log(log_level, f"Mode solver status: {status}")
            if verbose:
                console.log(f"Mode solver status: {status}")
            prev_status = status
        time.sleep(0.5)
        status = task.get_info().status

@momchil-flex
Copy link
Collaborator

So I think what you say makes sense but the point is that you used to run the processes async and only then each process would try to make a folder. Then, multiple calls to the api will happen and it can be arbitrary when some folders will get made and some processes will start seeing them.

But now you call the folder creation before you start the async run, and since the folder creation itself is sync, I would think you don't need an explicit sleep.

@prashkh
Copy link
Contributor Author

prashkh commented Oct 8, 2024

@momchil-flex you were right! Just adding the folder = Folder.create(folder_name=folder_name) fixed it. No need to add time delay :)

@momchil-flex
Copy link
Collaborator

Great! Could you update the PR?

@momchil-flex
Copy link
Collaborator

I guess I'll do it myself and merge.

@momchil-flex momchil-flex force-pushed the prash/run_batch_folder_fix branch from e219707 to e0072d8 Compare October 9, 2024 12:10
@prashkh
Copy link
Contributor Author

prashkh commented Oct 9, 2024

Thank you!

@momchil-flex momchil-flex merged commit a957619 into develop Oct 9, 2024
15 checks passed
@momchil-flex momchil-flex deleted the prash/run_batch_folder_fix branch October 9, 2024 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants