Skip to content

Conversation

@dstrain115
Copy link
Contributor

@dstrain115 dstrain115 commented Aug 6, 2025

  • 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).

Original work done by mpharrigan in #1678

- 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).
@dstrain115 dstrain115 marked this pull request as ready for review August 6, 2025 12:43
)


def test_get_soquet():
Copy link
Collaborator

Choose a reason for hiding this comment

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

thank you!

Copy link
Collaborator

@mpharrigan mpharrigan left a 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 :)

Comment on lines 524 to 525
We can uniquely address a Soquet by the arguments to this function.
Args:
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 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

Copy link
Contributor Author

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.
Copy link
Collaborator

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.

Copy link
Contributor Author

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.
Copy link
Collaborator

Choose a reason for hiding this comment

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

per bloq instance (?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Args:
reg_name: Name of the register
idx: Index of the register wite(s).
Copy link
Collaborator

Choose a reason for hiding this comment

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

wites -> wires

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

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
Copy link
Collaborator

Choose a reason for hiding this comment

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

instance -> bloq instance index (?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Comment on lines 223 to 225
random_handler: '_ClassicalValHandler' = _RandomClassicalValHandler(
rng=np.random.default_rng()
),
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 _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

Copy link
Contributor Author

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?

@dstrain115 dstrain115 changed the title Add classes for classical distribtuons Add support for simulation over classical distributions Aug 7, 2025
@dstrain115 dstrain115 merged commit 72dbba9 into quantumlib:main Aug 8, 2025
8 checks passed
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