-
Notifications
You must be signed in to change notification settings - Fork 61
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
Sabre with measurements #1084
Sabre with measurements #1084
Conversation
To make the Sabre transpiler work with qubits i have already modified the block decomposition to accept measurements. |
The Sabre transpiler with this PR will be able to corrrectly work with measurement gates. In particular final measurements can be given on multi qubits and registers are correctly matched. Intermediate measurements works correctly if acting on single qubits. When using multi qubit intermediate measurements they will be decomposed into single qubit measurements thus changing their register. However, as discussed with @Stavros, for now intermediate measurements are not suported on the hardware, so this issue can be addressed in the future. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1084 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 63 63
Lines 8862 8903 +41
=========================================
+ Hits 8862 8903 +41
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
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.
Thanks @Simone-Bordoni, just a handful of comments.
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.
In the test_sabre_intermediate_measurements
the transpiler is doing nothing I believe, as the CNOT(0,1)
involves qubits that are connected already. I tried to change this to CNOT(0,2)
to trigger the SWAP
insertion and it fails for me. I would change that test by adding the measurement to qubit 1 M(1)
and applying CNOT(0,2)
. This way you are sure that the measurement is moved and sabre is doing something.
The test_sabre_final_measurements
I would remove, instead, and add the final measurements testing to test_sabre_random_circuits
.
@pytest.mark.parametrize("gates", [10, 40])
@pytest.mark.parametrize("look", [0, 5])
@pytest.mark.parametrize("decay", [0.5, 1.0])
@pytest.mark.parametrize("placer", [Trivial, Random])
@pytest.mark.parametrize("connectivity", [star_connectivity(), grid_connectivity()])
def test_sabre_random_circuits(gates, look, decay, placer, connectivity):
placer = placer(connectivity=connectivity)
layout_circ = Circuit(5)
initial_layout = placer(layout_circ)
router = Sabre(connectivity=connectivity, lookahead=look, decay_lookahead=decay)
circuit = generate_random_circuit(nqubits=5, ngates=gates)
measurement = gates.M(np.random.choice(range(5), size=3, replace=False))
circuit.add(measurement)
transpiled_circuit, final_qubit_map = router(circuit, initial_layout)
assert router.added_swaps >= 0
assert_connectivity(connectivity, transpiled_circuit)
assert_placement(transpiled_circuit, final_qubit_map)
assert gates + router.added_swaps == transpiled_circuit.ngates
assert_circuit_equivalence(
original_circuit=circuit,
transpiled_circuit=transpiled_circuit,
final_map=final_qubit_map,
initial_map=initial_layout,
)
circuit_result = routed_circ.execute(nshots=100)
assert circuit_result.frequencies() == measurement.result.frequencies()
assert routed_circ.queue[-1].result is measurement.result
In
|
Thme measurement gate commutes with the CNOT (different qubits) so the order is irrelevant. |
Checklist: