Skip to content

CPU Saturation test (prerequisite for #1175 PR) - #1187

Closed
janko-petkovic wants to merge 7 commits into
sbi-dev:mainfrom
janko-petkovic:pre-1175-mutliproc-test
Closed

janko-petkovic wants to merge 7 commits into
sbi-dev:mainfrom
janko-petkovic:pre-1175-mutliproc-test

Conversation

@janko-petkovic

Copy link
Copy Markdown
Contributor

This branch includes an additional test aimed at highlighting the CPU usage while running a high number of simulations.
...

Does this close any currently open issues?

This is an addition that aims to give the devs a way to test the fix that will be proposed in the next days for the simulate_for_sbi function

Any relevant code examples, logs, error output, etc?

You don't need to let the test finish, it is just supposed to provide the workload.

Any other comments?

Remember that the testing is actually done by looking at the process manager / htop while the test is running.

Checklist

Put an x in the boxes that apply. You can also fill these out after creating
the PR. If you're unsure about any of them, don't hesitate to ask. We're here to
help! This is simply a reminder of what we are going to look for before merging
your code.

  • I have read and understood the contribution
    guidelines
  • I agree with re-licensing my contribution from AGPLv3 to Apache-2.0.
  • I have commented my code, particularly in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works
  • I have reported how long the new tests run and potentially marked them
    with pytest.mark.slow.
  • New and existing unit tests pass locally with my changes
  • I performed linting and formatting as described in the contribution
    guidelines
  • I rebased on main (or there are no conflicts with main)
  • For reviewer: The continuous deployment (CD) workflow are passing.

@janko-petkovic janko-petkovic changed the title Pre 1175 mutliproc test CPU Saturation test (prerequisite for #1175 PR) Jun 26, 2024
@codecov

codecov Bot commented Jun 26, 2024 •

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 75.61%. Comparing base (ba19688) to head (4601b04).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1187      +/-   ##
==========================================
- Coverage   84.55%   75.61%   -8.95%     
==========================================
  Files          96       96              
  Lines        7603     7603              
==========================================
- Hits         6429     5749     -680     
- Misses       1174     1854     +680     
Flag Coverage Δ
unittests 75.61% <ø> (-8.95%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

see 24 files with indirect coverage changes

@janfb janfb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great, thanks for starting this!
I added a couple of comments and question. We can also discuss in person if that's more efficient.

Comment on lines +30 to +32
for th in theta:
# time.sleep(0.05)
x.append(diagonal_linear_gaussian(th.reshape(1, -1)))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is the commented out sleep a left over?
Also, is the for-loop on purpose to make it slow?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The commented out sleep is a left over yes.
The for loop I left in there in case the test wanted to be run with a batched simulation.

Comment thread tests/cpu_saturation_test.py Resolved
Comment thread tests/cpu_saturation_test.py Outdated
# toc_joblib = time.time() - tic

# Allow joblib to be 50 percent slower due to overhead.
# assert toc_joblib <= toc_sp * 1.5

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why is this commented out?
If we know this fails (and will be fixed in the future), we could use an pytest.mark.xfail above.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You are correct, I didn't think about that.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is essentially the same test as above, no?
I am not sure what the purpose of the above test is then, but probably I am missing something.

Maybe, the new test above is just a temporary thing to see the saturation locally in htop?

@janko-petkovic janko-petkovic Jul 2, 2024 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is the old test that was already in the sbi library. The only thing I did here is to swap simulate_in_batches with simulate_for_sbi, since the former will not be used after the refactoring.
This test (multiprocessing_test) has the same purpose as before, checking that multiprocessing and batching actually work better than serial computation.

On the other hand, as you correctly noticed, cpu_saturation_test.py is meant just to verify that the joblib PR indeed made things better. In my opinion it can be safely removed afterwards.

@janfb

janfb commented Jul 21, 2024

Copy link
Copy Markdown
Contributor

I suggest, one the other PR #1188 is merged, we can merge main into this branch to then double check whether CPU saturation has improved with the fixes.
If yes, we can actually delete the cpu_saturation_test.py as it is not really a CI test. We only keep the changes to multiprocessing_test.py. Would you agree?

@janko-petkovic

Copy link
Copy Markdown
Contributor Author

I suggest, one the other PR #1188 is merged, we can merge main into this branch to then double check whether CPU saturation has improved with the fixes. If yes, we can actually delete the cpu_saturation_test.py as it is not really a CI test. We only keep the changes to multiprocessing_test.py. Would you agree?

Sure makes sense and keeps main history less cluttered. I'd then post the runtime differences in this thread.

@janko-petkovic

janko-petkovic commented Jul 22, 2024 •

Copy link
Copy Markdown
Contributor Author

Here are the performances before and after the simulate_for_sbi refactoring:

  • old implementation
    tqdm-old
  • new implementation
    tqdm

Interestingly, the CPU usage is not fully saturated in either case:

  • old implementation
    htop-old
  • new implementation
    htop

This could be due to the fact that the test is not computationally intensive, as other, heavier, simulations have shown to fully saturate CPU with the new implementation.

At this point, this branch has served its proof-of-concept purpose and can be deleted without merging (to the best of my understanding).

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.

2 participants