Skip to content

Commit be7a1a3

Browse files
more merges with Qiskit#13295; adding more Rustiq tests
1 parent 9c8b32d commit be7a1a3

3 files changed

Lines changed: 44 additions & 15 deletions

File tree

crates/accelerate/src/circuit_library/pauli_evolution.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ fn multi_qubit_evolution(
138138
.filter(|(p, _)| *p != 'z')
139139
.map(|(p, q)| match p {
140140
'x' => (StandardGate::HGate, smallvec![], smallvec![*q]),
141-
'y' => (StandardGate::SXdgGate, smallvec![], smallvec![*q]),
141+
'y' => (StandardGate::SXGate, smallvec![], smallvec![*q]),
142142
_ => unreachable!("Invalid Pauli string."), // "z" and "i" have been filtered out
143143
})
144144
.collect();
@@ -148,7 +148,7 @@ fn multi_qubit_evolution(
148148
.iter()
149149
.map(|(gate, _, qubit)| match gate {
150150
StandardGate::HGate => (StandardGate::HGate, smallvec![], qubit.clone()),
151-
StandardGate::SXdgGate => (StandardGate::SXGate, smallvec![], qubit.clone()),
151+
StandardGate::SXGate => (StandardGate::SXdgGate, smallvec![], qubit.clone()),
152152
_ => unreachable!("Invalid basis-changing Clifford."),
153153
})
154154
.collect();

test/python/circuit/library/test_pauli_feature_map.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -347,23 +347,23 @@ def test_pauli_xyz(self):
347347

348348
params = encoding.parameters
349349

350-
# q_0: ─────────────■────────────────────────■──────────────
351-
# ┌─────────┐┌─┴─┐ ┌─┴─┐┌──────────┐
352-
# q_1: ┤ Rx(π/2) ├┤ X ├──■──────────────■──┤ X ├┤ Rx(-π/2)
353-
# └─┬───┬──┘└───┘┌─┴─┐┌────────┐┌─┴─┐├───┤└──────────┘
354-
# q_2: ──┤ H ├────────┤ X ├┤ P(2.8) ├┤ X ├┤ H ├────────────
355-
# └───┘ └───┘└────────┘└───┘└───┘
350+
# q_0: ──────────■────────────────────────■────────
351+
# ┌──────┐┌─┴─┐ ┌─┴─┐┌────┐
352+
# q_1: ┤ √Xdg ├┤ X ├──■──────────────■──┤ X ├┤ √X
353+
# └─┬───┬┘└───┘┌─┴─┐┌────────┐┌─┴─┐├───┤└────┘
354+
# q_2: ──┤ H ├──────┤ X ├┤ P(2.8) ├┤ X ├┤ H ├──────
355+
# └───┘ └───┘└────────┘└───┘└───┘
356356
# X on the most-significant, bottom qubit, Z on the top
357357
ref = QuantumCircuit(3)
358358
ref.h(range(3))
359359
ref.h(2)
360-
ref.rx(np.pi / 2, 1)
360+
ref.sxdg(1)
361361
ref.cx(0, 1)
362362
ref.cx(1, 2)
363363
ref.p(2 * np.prod([np.pi - p for p in params]), 2)
364364
ref.cx(1, 2)
365365
ref.cx(0, 1)
366-
ref.rx(-np.pi / 2, 1)
366+
ref.sx(1)
367367
ref.h(2)
368368

369369
self.assertEqual(ref, encoding)
@@ -483,13 +483,13 @@ def test_dict_entanglement(self):
483483
ref.cx(1, 2)
484484
ref.h([1, 2])
485485

486-
ref.rx(np.pi / 2, range(3))
486+
ref.sxdg(range(3))
487487
ref.cx(0, 1)
488488
ref.cx(1, 2)
489489
ref.p(2 * np.prod([np.pi - xi for xi in x]), 2)
490490
ref.cx(1, 2)
491491
ref.cx(0, 1)
492-
ref.rx(-np.pi / 2, range(3))
492+
ref.sx(range(3))
493493

494494
self.assertEqual(ref, circuit)
495495

test/python/transpiler/test_high_level_synthesis.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2614,14 +2614,43 @@ def test_supported_names(self):
26142614
@data("default", "rustiq")
26152615
def test_correctness(self, plugin_name):
26162616
"""Test that all plugins return a correct Operator"""
2617-
op = SparsePauliOp(["XXX", "YYY", "IZZ"], coeffs=[1, 2, 3])
2617+
op = SparsePauliOp(["XXX", "YYY", "IZZ", "XZY"], coeffs=[1, 2, 3, 4])
26182618
qc = QuantumCircuit(6)
26192619
qc.append(PauliEvolutionGate(op), [1, 2, 4])
26202620
hls_config = HLSConfig(PauliEvolution=[plugin_name])
26212621
hls_pass = HighLevelSynthesis(hls_config=hls_config)
26222622
qct = hls_pass(qc)
2623-
# self.assertEqual(Operator(qc), Operator(qct))
2624-
self.assertTrue(Operator(qc).equiv(Operator(qct)))
2623+
self.assertEqual(Operator(qc), Operator(qct))
2624+
2625+
def test_rustiq_options(self):
2626+
"""Test important non-default Rustiq options."""
2627+
op = SparsePauliOp(["XXXX", "YYYY", "ZZZZ"], coeffs=[1, 2, 3])
2628+
qc = QuantumCircuit(6)
2629+
qc.append(PauliEvolutionGate(op), [1, 2, 3, 4])
2630+
2631+
# These calls to Rustiq are deterministic.
2632+
# On the one hand, we may need to change these tests if we switch
2633+
# to a newer version of Rustiq that implements different heuristics.
2634+
# On the other hand, these tests serve to show that the options
2635+
# have the desired effect of reducing the number of CX-gates.
2636+
with self.subTest("default_options"):
2637+
hls_config = HLSConfig(PauliEvolution=[("rustiq", {"upto_phase": False})])
2638+
hls_pass = HighLevelSynthesis(hls_config=hls_config)
2639+
qct = hls_pass(qc)
2640+
cnt_ops = qct.count_ops()
2641+
self.assertEqual(cnt_ops["cx"], 10)
2642+
with self.subTest("upto_phase"):
2643+
hls_config = HLSConfig(PauliEvolution=[("rustiq", {"upto_phase": True})])
2644+
hls_pass = HighLevelSynthesis(hls_config=hls_config)
2645+
qct = hls_pass(qc)
2646+
cnt_ops = qct.count_ops()
2647+
self.assertEqual(cnt_ops["cx"], 9)
2648+
with self.subTest("upto_clifford"):
2649+
hls_config = HLSConfig(PauliEvolution=[("rustiq", {"upto_clifford": True})])
2650+
hls_pass = HighLevelSynthesis(hls_config=hls_config)
2651+
qct = hls_pass(qc)
2652+
cnt_ops = qct.count_ops()
2653+
self.assertEqual(cnt_ops["cx"], 5)
26252654

26262655

26272656
if __name__ == "__main__":

0 commit comments

Comments
 (0)