Skip to content

Commit

Permalink
Add test case to validate the rust->Python gate conversion (#12623)
Browse files Browse the repository at this point in the history
This commit adds a test to the test_rust_equivalence module to assert
that the Python gate objects returned from the Rust CircuitData is
the correct type.
  • Loading branch information
mtreinish authored Jun 26, 2024
1 parent 26680dc commit 39b2c90
Showing 1 changed file with 16 additions and 1 deletion.
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

0 comments on commit 39b2c90

Please sign in to comment.