-
Notifications
You must be signed in to change notification settings - Fork 80
Add bloq for Measurement in the X basis #1683
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
Conversation
- 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
| with pytest.raises(ValueError, match='MeasX imparts a phase'): | ||
| _ = bloq.call_classically(q=0) |
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.
👍
| _ = bloq.on_classical_vals(q=2) | ||
|
|
||
| results = [ | ||
| do_phased_classical_simulation(bloq, {'q': 0}, 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.
what do you think about seeding our random generator in tests? usually we do; and theoretically line 151 or 152 could fail
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.
Added seed.
| # 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) |
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 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]]
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.
Ha, yeah, copied from Z-basis test and fixed the operators but not the comments. Fixed now.
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.
wooo
phase if 1 is measured.
Original work done by mpharrigan in #1678