-
Notifications
You must be signed in to change notification settings - Fork 74
Add support for simulation over classical distributions #1682
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
base: main
Are you sure you want to change the base?
Conversation
- These classes will be used within the classical simulator to represent distributions of classical measurements. - For instance, if measuring in the X-basis, you will get a random result (0 or 1) possibly with an additional phase. - This is part of the measurement-based uncomputation feature (MBUC).
) | ||
|
||
|
||
def test_get_soquet(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sweeeeeet
some doc nits
and: maybe the PR title needs to be updated since this also includes the logic updates to support simulation with distributions over classical variables. Also there's a typo in the PR title :)
qualtran/_infra/composite_bloq.py
Outdated
We can uniquely address a Soquet by the arguments to this function. | ||
Args: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need some newlines in this docstring for it to be parsed correctly; although this is a private function so it won't actually show up anywhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
class _FixedClassicalValHandler(_ClassicalValHandler): | ||
"""Returns a random classical value using a fixed value per instance. | ||
|
||
Useful for deterministic testing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Args:
binst_i_to_val: mapping from BloqInstance.i
instance indices to the fixed classical value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
qualtran/simulation/classical_sim.py
Outdated
|
||
|
||
class _FixedClassicalValHandler(_ClassicalValHandler): | ||
"""Returns a random classical value using a fixed value per instance. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
per bloq instance (?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
qualtran/simulation/classical_sim.py
Outdated
|
||
Args: | ||
reg_name: Name of the register | ||
idx: Index of the register wite(s). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wites -> wires
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
qualtran/simulation/classical_sim.py
Outdated
) -> 'PhasedClassicalSimState': | ||
"""Initiate a classical simulation from a CompositeBloq. | ||
|
||
Args: | ||
cbloq: The composite bloq | ||
vals: A mapping of input register name to classical value to serve as inputs to the | ||
procedure. | ||
rng: A random number generator to use for classical random values, such a np.random. | ||
fixed_random_vals: A dictionary of instance to values to perform fixed calculation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instance -> bloq instance index (?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
qualtran/simulation/classical_sim.py
Outdated
random_handler: '_ClassicalValHandler' = _RandomClassicalValHandler( | ||
rng=np.random.default_rng() | ||
), |
There was a problem hiding this comment.
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 _BannedClassicalValHandler
, no? throughout these PRs, I tried to leave the "normal" classical simulator the same, non-phased, and deterministic; and the fancy stuff is "opt-in" by using the PhasedClassicalSimulator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's awfully difficult to use though if you set that as the default, since the top-level functions don't have a super great way to pipe in a random_handler (and the random_handler is private).
Are you sure about this?
Original work done by mpharrigan in #1678