Skip to content

Refactor for clarity, add comments.#57

Open
matthew-brett wants to merge 6 commits into
numfocus:mainfrom
matthew-brett:refactor-algorithm
Open

Refactor for clarity, add comments.#57
matthew-brett wants to merge 6 commits into
numfocus:mainfrom
matthew-brett:refactor-algorithm

Conversation

@matthew-brett

Copy link
Copy Markdown

We were finding it hard to follow the algorithm, and this seemed generally undesirable, so we have attempted a refactor for greater clarity.

We've also used the more standard RNG instance pattern for the random number generation.

The tests are failing, but this seems also to be true of main.

@matthew-brett

Copy link
Copy Markdown
Author

For the tests - I wasn't sure what to do. I think the original tests are assuming that something like the following will always give the same output value i:

# In the test function.
np.random.seed(2025)
# In `select_proposals`
np.random.seed(None)
i = np.random.choice(1000)  # e.g.

but in my hands, that is not true. Accordingly the tests on main are failing with random actual output differing from expected. On this branch the tests fail with specific and repeatable actual output. I'm happy to check the expected output by hand if that's helpful.

We were confused by the algorithm, and this seemed generally
undesirable, so we have attempted a refactor for greater clarity.

We've also used the more standard RNG instance pattern for the random
number generation.

The tests are failing, but this seems also to be true of `main`.

@lucascolley lucascolley left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM, thanks Matthew!

@matthew-brett

Copy link
Copy Markdown
Author

@lucascolley - what say you for the tests?

@lucascolley

Copy link
Copy Markdown

#57 (comment) sounds good to me. What is the diff to make the tests pass? https://github.com/15r10nk/inline-snapshot could make that easier to find.

@matthew-brett

Copy link
Copy Markdown
Author

OK - I've added some tests to assert the proportions match the weights, and updated the test output to the current test output.

I did a little more refactoring of the project random selection for clarity.

I've also added a test.yml file as .github/tests.pending, because I can't push with the workflow enabled:

 ! [remote rejected] refactor-algorithm -> refactor-algorithm (refusing to allow a Personal Access Token to create or update workflow `.github/workflows/test.yml` without `workflow` scope)
error: failed to push some refs to 'https://github.com/matthew-brett/small-development-grant-proposals'

Although doing it in one go is neater, perhaps it will delay review by
forcing reviewers to confirm it gives the same output.
@matthew-brett

Copy link
Copy Markdown
Author

I've reverted the algorithm to the stepwise selection procedure; ordering and then confirming is neater to my eye, but I thought it would require extra review work to confirm it gives equivalent results. I did use inline_snapshot for the tests.

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