Skip to content
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

Add test case to validate the rust->Python gate conversion #12623

Merged
merged 3 commits into from
Jun 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion test/python/circuit/test_rust_equivalence.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import numpy as np

from qiskit.circuit import QuantumCircuit
from qiskit.circuit import QuantumCircuit, CircuitInstruction
from qiskit.circuit.library.standard_gates import get_standard_gate_name_mapping

SKIP_LIST = {"rx", "ry", "ecr"}
Expand All @@ -39,6 +39,21 @@ def setUp(self):
gate = gate.base_class(*[pi] * len(gate.params))
qc.append(gate, list(range(gate.num_qubits)))

def test_gate_cross_domain_conversion(self):
"""Test the rust -> python conversion returns the right class."""
for name, gate_class in self.standard_gates.items():
standard_gate = getattr(gate_class, "_standard_gate", None)
if standard_gate is None:
# Gate not in rust yet or no constructor method
continue
with self.subTest(name=name):
qc = QuantumCircuit(standard_gate.num_qubits)
qc._append(
CircuitInstruction(standard_gate, qubits=qc.qubits, params=gate_class.params)
)
self.assertEqual(qc.data[0].operation.base_class, gate_class.base_class)
self.assertEqual(qc.data[0].operation, gate_class)

def test_definitions(self):
"""Test definitions are the same in rust space."""
for name, gate_class in self.standard_gates.items():
Expand Down
Loading