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

add seed list feature #197

Merged
merged 4 commits into from
Nov 8, 2023
Merged

add seed list feature #197

merged 4 commits into from
Nov 8, 2023

Conversation

cqc-melf
Copy link
Collaborator

@cqc-melf cqc-melf commented Nov 2, 2023

Fixes the problem discussed in CQCL/pytket-qulacs#44

@cqc-melf cqc-melf force-pushed the feature/rng-seed-list branch 2 times, most recently from 11ce6a6 to 53cb386 Compare November 3, 2023 16:56
@cqc-melf cqc-melf force-pushed the feature/rng-seed-list branch from 461b920 to d8cd3f1 Compare November 3, 2023 17:34
@cqc-melf cqc-melf marked this pull request as ready for review November 3, 2023 17:42
@cqc-melf cqc-melf requested a review from cqc-alec November 3, 2023 17:42
@cqc-alec
Copy link
Collaborator

cqc-alec commented Nov 6, 2023

Why is it necessary to provide a list of seeds, instead of just one seed which gets auto-incremented on each submission? This would give reproducibility and (assuming a half-decent PRNG) remove any bias. Is there a use case I'm missing?

@cqc-melf
Copy link
Collaborator Author

cqc-melf commented Nov 6, 2023

My understanding is that is this only taking affect when doing batch submissions. I was thinking of the case that you want to rerun your experiments for only a subset of your initial input. When doing auto incremented seeds this would not work.

I think this is an unlikely use case, and quite confusing to use. If I understand the code, batching here is done by grouping together circuits with the same number of shots; so you would need one seed per distinct value in your n_shots list, and when running a subset you would be very restricted in which subsets you could run (while still having reproducibility). All this would need to be explained in the docs. I think I'd rather keep things simple instead of adding a feature for which there's no clear need.

Copy link
Collaborator

@cqc-alec cqc-alec left a comment

Choose a reason for hiding this comment

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

See #197 (comment) . (Sorry, looks like I edited your comment instead of adding a new one.)

@cqc-melf
Copy link
Collaborator Author

cqc-melf commented Nov 7, 2023

My understanding is that is this only taking affect when doing batch submissions. I was thinking of the case that you want to rerun your experiments for only a subset of your initial input. When doing auto incremented seeds this would not work.

I think this is an unlikely use case, and quite confusing to use. If I understand the code, batching here is done by grouping together circuits with the same number of shots; so you would need one seed per distinct value in your n_shots list, and when running a subset you would be very restricted in which subsets you could run (while still having reproducibility). All this would need to be explained in the docs. I think I'd rather keep things simple instead of adding a feature for which there's no clear need.

The list of shots contains one entry per circuit and in the same way I am expecting one entry in the seeds list per circuit.

If all the seeds are identical (or the user just gives one value like before) we can do the submissions of circuits batches using the qiskit-batch interface (this still works in the same way as before) (see https://github.com/CQCL/pytket-qiskit/pull/197/files#diff-8ccf4df5e4b2a5aa355a1a8a3086114f67945bdab047dc9f75ed25ed7dfd0850R78 )

If there are different seeds given, doing the creation of the qiskit-batches needs to be done differently: each batch now only contains exactly one circuit and the corresponding seed and shot number. (see https://github.com/CQCL/pytket-qiskit/pull/197/files#diff-8ccf4df5e4b2a5aa355a1a8a3086114f67945bdab047dc9f75ed25ed7dfd0850R92 )

If we want to do something like autoincrementing the seeds, we would need to break the qiskit-batch creation anyway. I have not found a way to have different seeds for the list of circuits in a qiskit batch.

So I think the user is free to choose any subset they would like and this would still work. (But if you think this is not a use case that is going to happen, I am happy to change to auto incrementing the seed)

@cqc-alec
Copy link
Collaborator

cqc-alec commented Nov 7, 2023

The list of shots contains one entry per circuit and in the same way I am expecting one entry in the seeds list per circuit.

Ah, this is indeed the case, but only because you have changed the logic of _batch_circuits(). It used to group circuits having the same number of shots together, but now it just puts one circuit in each batch (unless all the seeds are the same).

I assume this behaviour was in order to make most efficient use of the IBMQ interface so I think we should keep it.

@cqc-melf
Copy link
Collaborator Author

cqc-melf commented Nov 7, 2023

The list of shots contains one entry per circuit and in the same way I am expecting one entry in the seeds list per circuit.

Ah, this is indeed the case, but only because you have changed the logic of _batch_circuits(). It used to group circuits having the same number of shots together, but now it just puts one circuit in each batch (unless all the seeds are the same).

I assume this behaviour was in order to make most efficient use of the IBMQ interface so I think we should keep it.

From my understanding the IBMQ interface only allows to set one seed for each qiskit-batch, so we would have to do equal seeds per qiskit batch. That would show the same issue as we had before, do we want to do that and would not be compatible with auto incrementing seeds as well?

@cqc-alec
Copy link
Collaborator

cqc-alec commented Nov 7, 2023

From my understanding the IBMQ interface only allows to set one seed for each qiskit-batch, so we would have to do equal seeds per qiskit batch. That would show the same issue as we had before, do we want to do that and would not be compatible with auto incrementing seeds as well?

What is the issue with one seed per qiskit batch? I would assume that the seed is used once to seed a global PRNG for the whole batch, not one PRNG per circuit.

@cqc-alec
Copy link
Collaborator

cqc-alec commented Nov 7, 2023

If a user wants to have reproducibility at the sub-batch level, I think they need to design that into their workflow from the beginning: each call to process_circuits() should be reproducible, and therefore only needs a single seed.

@cqc-melf
Copy link
Collaborator Author

cqc-melf commented Nov 7, 2023

I have removed the list feature and added a parameter for auto inc in 080f453

But I am not fully sure this is helpful like this, I would assume that this might still encourage people to not use batch submission when they want to reproduce results reliably.

@cqc-melf cqc-melf requested a review from cqc-alec November 8, 2023 09:24
"""
See :py:meth:`pytket.backends.Backend.process_circuits`.
Supported kwargs: `seed`, `postprocess`, `seed_auto_increase`.
seed_auto_increase=True will automatically increase the seed by one for the
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this should be automatic (definitely the default behaviour, but I don't see a reasonable use case for not incrementing the seed, which introduces biases in the results, so no need to add a new kwarg).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I did not wanted to do this by default because that would stop old runs from being reproducible, if that is not a concern I am happy to remove the parameter and always do the auto inc. The use case for the parameter I see is being compatible with reproducing old runs.

Copy link
Collaborator

Choose a reason for hiding this comment

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

At least they will still be reproducible if the same version numbers (of pytket-qiskit, qiskit, etc) are used.

@cqc-alec
Copy link
Collaborator

cqc-alec commented Nov 8, 2023

I have removed the list feature and added a parameter for auto inc in 080f453

But I am not fully sure this is helpful like this, I would assume that this might still encourage people to not use batch submission when they want to reproduce results reliably.

If incrementing the seed is automatic then every call to process_circuits() should be reproducible (if the same seed is used).

@cqc-melf cqc-melf requested a review from cqc-alec November 8, 2023 13:24
@@ -9,6 +9,7 @@ unreleased
* Update qiskit-ibm-runtime version to 0.13.0.
* Update qiskit-aer version to 0.13.0.
* Introduce dependency on qiskit-algorithms.
* Add option for automatic incrementing seed on ``process_circuits()``.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Update description in changelog.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done in 85489ef

Comment on lines 244 to 245
Supported kwargs: `seed`, `postprocess`, `seed_auto_increase`.
seed_auto_increase=True will automatically increase the seed by one for the
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done in 85489ef

Comment on lines 292 to 293
if kwargs.get("seed_auto_increase") and type(seed) is int:
seed += 1
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if kwargs.get("seed_auto_increase") and type(seed) is int:
seed += 1
seed += 1

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done in 85489ef

Comment on lines 132 to 134
Supported kwargs: `seed`, `postprocess`, `seed_auto_increase`.
seed_auto_increase=True will automatically increase the seed by one for the
different batches when more than one circuit is submitted
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done in 85489ef

Comment on lines 180 to 181
if kwargs.get("seed_auto_increase") and type(seed) is int:
seed += 1
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if kwargs.get("seed_auto_increase") and type(seed) is int:
seed += 1
seed += 1

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done in 85489ef

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I needed to keep the type check for mypy. (and to make sure I am not incrementing when the seed is set to none)

@cqc-melf cqc-melf requested a review from cqc-alec November 8, 2023 14:25
@cqc-melf cqc-melf marked this pull request as draft November 8, 2023 14:33
@cqc-melf cqc-melf force-pushed the feature/rng-seed-list branch from 460d83c to e9d0627 Compare November 8, 2023 14:37
@cqc-melf cqc-melf marked this pull request as ready for review November 8, 2023 14:42
@cqc-melf cqc-melf merged commit 45b42d3 into develop Nov 8, 2023
7 checks passed
@cqc-melf cqc-melf deleted the feature/rng-seed-list branch March 26, 2024 14:46
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