Skip to content

Commit

Permalink
more merges with Qiskit#13295; adding more Rustiq tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderivrii committed Oct 31, 2024
1 parent 9c8b32d commit be7a1a3
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 15 deletions.
4 changes: 2 additions & 2 deletions crates/accelerate/src/circuit_library/pauli_evolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ fn multi_qubit_evolution(
.filter(|(p, _)| *p != 'z')
.map(|(p, q)| match p {
'x' => (StandardGate::HGate, smallvec![], smallvec![*q]),
'y' => (StandardGate::SXdgGate, smallvec![], smallvec![*q]),
'y' => (StandardGate::SXGate, smallvec![], smallvec![*q]),
_ => unreachable!("Invalid Pauli string."), // "z" and "i" have been filtered out
})
.collect();
Expand All @@ -148,7 +148,7 @@ fn multi_qubit_evolution(
.iter()
.map(|(gate, _, qubit)| match gate {
StandardGate::HGate => (StandardGate::HGate, smallvec![], qubit.clone()),
StandardGate::SXdgGate => (StandardGate::SXGate, smallvec![], qubit.clone()),
StandardGate::SXGate => (StandardGate::SXdgGate, smallvec![], qubit.clone()),
_ => unreachable!("Invalid basis-changing Clifford."),
})
.collect();
Expand Down
20 changes: 10 additions & 10 deletions test/python/circuit/library/test_pauli_feature_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,23 +347,23 @@ def test_pauli_xyz(self):

params = encoding.parameters

# q_0: ─────────────■────────────────────────■──────────────
# ┌─────────┐┌─┴─┐ ┌─┴─┐┌──────────┐
# q_1: ┤ Rx(π/2) ├┤ X ├──■──────────────■──┤ X ├┤ Rx(-π/2)
# └─┬───┬──┘└───┘┌─┴─┐┌────────┐┌─┴─┐├───┤└──────────┘
# q_2: ──┤ H ├────────┤ X ├┤ P(2.8) ├┤ X ├┤ H ├────────────
# └───┘ └───┘└────────┘└───┘└───┘
# q_0: ──────────■────────────────────────■────────
# ┌──────┐┌─┴─┐ ┌─┴─┐┌────┐
# q_1: ┤ √Xdg ├┤ X ├──■──────────────■──┤ X ├┤ √X
# └─┬───┬┘└───┘┌─┴─┐┌────────┐┌─┴─┐├───┤└────┘
# q_2: ──┤ H ├──────┤ X ├┤ P(2.8) ├┤ X ├┤ H ├──────
# └───┘ └───┘└────────┘└───┘└───┘
# X on the most-significant, bottom qubit, Z on the top
ref = QuantumCircuit(3)
ref.h(range(3))
ref.h(2)
ref.rx(np.pi / 2, 1)
ref.sxdg(1)
ref.cx(0, 1)
ref.cx(1, 2)
ref.p(2 * np.prod([np.pi - p for p in params]), 2)
ref.cx(1, 2)
ref.cx(0, 1)
ref.rx(-np.pi / 2, 1)
ref.sx(1)
ref.h(2)

self.assertEqual(ref, encoding)
Expand Down Expand Up @@ -483,13 +483,13 @@ def test_dict_entanglement(self):
ref.cx(1, 2)
ref.h([1, 2])

ref.rx(np.pi / 2, range(3))
ref.sxdg(range(3))
ref.cx(0, 1)
ref.cx(1, 2)
ref.p(2 * np.prod([np.pi - xi for xi in x]), 2)
ref.cx(1, 2)
ref.cx(0, 1)
ref.rx(-np.pi / 2, range(3))
ref.sx(range(3))

self.assertEqual(ref, circuit)

Expand Down
35 changes: 32 additions & 3 deletions test/python/transpiler/test_high_level_synthesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -2614,14 +2614,43 @@ def test_supported_names(self):
@data("default", "rustiq")
def test_correctness(self, plugin_name):
"""Test that all plugins return a correct Operator"""
op = SparsePauliOp(["XXX", "YYY", "IZZ"], coeffs=[1, 2, 3])
op = SparsePauliOp(["XXX", "YYY", "IZZ", "XZY"], coeffs=[1, 2, 3, 4])
qc = QuantumCircuit(6)
qc.append(PauliEvolutionGate(op), [1, 2, 4])
hls_config = HLSConfig(PauliEvolution=[plugin_name])
hls_pass = HighLevelSynthesis(hls_config=hls_config)
qct = hls_pass(qc)
# self.assertEqual(Operator(qc), Operator(qct))
self.assertTrue(Operator(qc).equiv(Operator(qct)))
self.assertEqual(Operator(qc), Operator(qct))

def test_rustiq_options(self):
"""Test important non-default Rustiq options."""
op = SparsePauliOp(["XXXX", "YYYY", "ZZZZ"], coeffs=[1, 2, 3])
qc = QuantumCircuit(6)
qc.append(PauliEvolutionGate(op), [1, 2, 3, 4])

# These calls to Rustiq are deterministic.
# On the one hand, we may need to change these tests if we switch
# to a newer version of Rustiq that implements different heuristics.
# On the other hand, these tests serve to show that the options
# have the desired effect of reducing the number of CX-gates.
with self.subTest("default_options"):
hls_config = HLSConfig(PauliEvolution=[("rustiq", {"upto_phase": False})])
hls_pass = HighLevelSynthesis(hls_config=hls_config)
qct = hls_pass(qc)
cnt_ops = qct.count_ops()
self.assertEqual(cnt_ops["cx"], 10)
with self.subTest("upto_phase"):
hls_config = HLSConfig(PauliEvolution=[("rustiq", {"upto_phase": True})])
hls_pass = HighLevelSynthesis(hls_config=hls_config)
qct = hls_pass(qc)
cnt_ops = qct.count_ops()
self.assertEqual(cnt_ops["cx"], 9)
with self.subTest("upto_clifford"):
hls_config = HLSConfig(PauliEvolution=[("rustiq", {"upto_clifford": True})])
hls_pass = HighLevelSynthesis(hls_config=hls_config)
qct = hls_pass(qc)
cnt_ops = qct.count_ops()
self.assertEqual(cnt_ops["cx"], 5)


if __name__ == "__main__":
Expand Down

0 comments on commit be7a1a3

Please sign in to comment.