Skip to content

Conversation

@dstrain115
Copy link
Contributor

  • MeasX measures a qubit in the X basis.
  • If simulated classically, this returns a classical distribution of 0 and 1 with a possible
    phase if 1 is measured.

Original work done by mpharrigan in #1678

- MeasX measures a qubit in the X basis.
- If simulated classically, this returns a
classical distribution of 0 and 1 with a possible
phase if 1 is measured.

Original work done by mpharrigan in quantumlib#1678
@dstrain115 dstrain115 marked this pull request as ready for review August 9, 2025 12:54
Comment on lines +138 to +139
with pytest.raises(ValueError, match='MeasX imparts a phase'):
_ = bloq.call_classically(q=0)
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

_ = bloq.on_classical_vals(q=2)

results = [
do_phased_classical_simulation(bloq, {'q': 0}, 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.

what do you think about seeding our random generator in tests? usually we do; and theoretically line 151 or 152 could fail

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added seed.

Comment on lines 182 to 207
# Zero -> Zero
bb = BloqBuilder()
q = bb.add(ZeroState())
c = bb.add(MeasX(), q=q)
cbloq = bb.finalize(c=c)
rho = cbloq.tensor_contract(superoperator=True)
should_be = np.asarray([[0.5, 0], [0, 0.5]])
np.testing.assert_allclose(rho, should_be, atol=1e-8)

# One -> One
bb = BloqBuilder()
q = bb.add(OneState())
c = bb.add(MeasX(), q=q)
cbloq = bb.finalize(c=c)
rho = cbloq.tensor_contract(superoperator=True)
should_be = np.asarray([[0.5, 0], [0, 0.5]])
np.testing.assert_allclose(rho, should_be, atol=1e-8)

# Plus -> mixture
bb = BloqBuilder()
q = bb.add(PlusState())
c = bb.add(MeasX(), q=q)
cbloq = bb.finalize(c=c)
rho = cbloq.tensor_contract(superoperator=True)
should_be = np.asarray([[1, 0], [0, 0]])
np.testing.assert_allclose(rho, should_be, atol=1e-8)
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 these tests are correct, but the comments are not

Measuring the zero ket in the x basis gives fully-mixed state (the identity matrix); as does measuring the one ket.
Measuring the plus state in the x basis gives you a deterministic "0" result |0><0| = [[1,0],[0,0]]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ha, yeah, copied from Z-basis test and fixed the operators but not the comments. Fixed now.

@dstrain115 dstrain115 requested a review from mpharrigan August 11, 2025 22:36
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.

wooo

@dstrain115 dstrain115 merged commit 9b8585a into quantumlib:main Aug 12, 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