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

Port TwoQubitControlledUDecomposer to rust #13139

Merged
merged 31 commits into from
Nov 13, 2024
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
2e3a383
replace calls to TwoQubitWeylDecomposition by calling rust functions
ShellyGarion Sep 12, 2024
7ab59b4
fix failing test
ShellyGarion Sep 12, 2024
cbc9b9d
Merge branch 'main' into two_qubit_decomp
ShellyGarion Oct 8, 2024
285a91d
add code for TwoQubitControlledUDecomposer in rust
ShellyGarion Oct 8, 2024
18000fe
Merge branch 'main' into two_qubit_decomp
ShellyGarion Oct 9, 2024
14c4a56
update try_inverse to inverse
ShellyGarion Oct 9, 2024
eb1b928
fix rust code. add rust docstrings
ShellyGarion Oct 9, 2024
c9b7553
remove python code
ShellyGarion Oct 9, 2024
71caa9e
update unitary in call
ShellyGarion Oct 9, 2024
eb4968b
handle global_phase
ShellyGarion Oct 10, 2024
a2943c9
minor fix
ShellyGarion Oct 10, 2024
7acb09a
fix lint
ShellyGarion Oct 10, 2024
e532c8a
set self.rxx_equivalent_gate
ShellyGarion Oct 15, 2024
3182838
check that rxx_equivalent_gate is a standard gate
ShellyGarion Oct 15, 2024
59ef018
iterating over test_angles and scales
ShellyGarion Oct 15, 2024
1ceb94e
add Vec capacity
ShellyGarion Oct 15, 2024
9ac68b1
remove invert variable
ShellyGarion Oct 15, 2024
6ad3869
move comments from Python to Rust code
ShellyGarion Oct 15, 2024
ebc0e73
remove new_inner function, move code into new
ShellyGarion Oct 15, 2024
02cd73e
call returns a CircuitData
ShellyGarion Oct 17, 2024
71d4b60
Merge remote-tracking branch 'origin/main' into two_qubit_decomp
mtreinish Oct 29, 2024
f46edbe
Support custom gates for decomposition too
mtreinish Oct 29, 2024
2e57608
Remove bare panics
mtreinish Oct 29, 2024
319c6e1
Merge branch 'main' into two_qubit_decomp
mtreinish Oct 29, 2024
7e0c2a2
Undo debug testing for invalid custom gate check
mtreinish Oct 29, 2024
7769833
Fix lint
mtreinish Oct 29, 2024
af17ab8
Fix python lint
mtreinish Oct 30, 2024
06c3da4
add default fidelity value
ShellyGarion Nov 12, 2024
ee3e88e
add more gates for the tests
ShellyGarion Nov 12, 2024
1bb0616
assert that CustomXYGate raises an error
ShellyGarion Nov 12, 2024
8949f7f
update assertion in test
ShellyGarion Nov 13, 2024
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
33 changes: 32 additions & 1 deletion test/python/synthesis/test_synthesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@
import unittest
import contextlib
import logging
import math
import numpy as np
import scipy
import scipy.stats
from ddt import ddt, data

from qiskit import QiskitError, transpile
from qiskit.dagcircuit.dagcircuit import DAGCircuit
from qiskit.circuit import QuantumCircuit, QuantumRegister
from qiskit.circuit import QuantumCircuit, QuantumRegister, Gate
from qiskit.circuit.parameterexpression import ParameterValueType
from qiskit.converters import dag_to_circuit, circuit_to_dag
from qiskit.circuit.library import (
HGate,
Expand Down Expand Up @@ -1460,6 +1462,35 @@ def __init__(self, theta, label=None):
circ = decomposer(unitary)
self.assertEqual(Operator(unitary), Operator(circ))

def test_unitary_custom_gate_raises(self):
"""Test that a custom gate raises an exception, as it's not equivalent to an RXX gate"""

class CustomXYGate(Gate):
"""Custom Gate subclass that's not a standard gate and not RXX equivalent"""

_standard_gate = None

def __init__(self, theta: ParameterValueType, label=None):
"""Create new custom rotstion XY gate."""
super().__init__("MyCustomXYGate", 2, [theta])

def __array__(self, dtype=None):
"""Return a Numpy.array for the custom gate."""
theta = self.params[0]
cos = math.cos(theta)
isin = 1j * math.sin(theta)
return np.array(
[[1, 0, 0, 0], [0, cos, -isin, 0], [0, -isin, cos, 0], [0, 0, 0, 1]],
dtype=dtype,
)

def inverse(self, annotated: bool = False):
return CustomXYGate(-self.params[0])

with self.assertRaises(QiskitError) as exc:
_ = TwoQubitControlledUDecomposer(CustomXYGate)
self.assertIn("Specialization: ControlledEquiv calculated fidelity", exc.exception.message)


class TestDecomposeProductRaises(QiskitTestCase):
"""Check that exceptions are raised when 2q matrix is not a product of 1q unitaries"""
Expand Down