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

Store AceCR properties in self.params #952

Merged
merged 3 commits into from
May 30, 2024
Merged
Changes from 1 commit
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
45 changes: 26 additions & 19 deletions qiskit-superstaq/qiskit_superstaq/custom_gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,52 +45,59 @@ def __init__(
params.append(sandwich_rx_rads)
super().__init__(name, 2, params, label=label)

self.rads = rads
self.sandwich_rx_rads = sandwich_rx_rads
self.params = params

dowusu-antwi marked this conversation as resolved.
Show resolved Hide resolved
def inverse(self) -> AceCR:
"""Inverts the AceCR gate.

Returns:
The inverse AceCR gate.
"""
return AceCR(self.rads, -self.sandwich_rx_rads, label=self.label)
if len(self.params) > 1:
return AceCR(self.params[0], -self.params[1], label=self.label)
return AceCR(self.params[0], label=self.label)

def _define(self) -> None:
"""Stores the qiskit circuit definition of the AceCR gate."""
qc = qiskit.QuantumCircuit(2, name=self.name)
qc.rzx(self.rads / 2, 0, 1)
qc.rzx(self.params[0] / 2, 0, 1)
qc.x(0)
if self.sandwich_rx_rads:
qc.rx(self.sandwich_rx_rads, 1)
qc.rzx(-self.rads / 2, 0, 1)
if len(self.params) > 1:
qc.rx(self.params[1], 1)
qc.rzx(-self.params[0] / 2, 0, 1)
self.definition = qc

def __array__(self, dtype: type | None = None) -> npt.NDArray[np.bool_]:
"""Returns an array for the AceCR gate."""
return qiskit.quantum_info.Operator(self.definition).data

def __repr__(self) -> str:
rads = self.params[0]
sandwich_rx_rads = 0 if len(self.params) < 2 else self.params[1]
args = []
if self.rads != np.pi / 2:
args.append(f"rads={self.rads!r}")
if self.sandwich_rx_rads != 0:
args.append(f"sandwich_rx_rads={self.sandwich_rx_rads!r}")
if rads != np.pi / 2:
args.append(f"rads={rads!r}")
if sandwich_rx_rads != 0:
args.append(f"sandwich_rx_rads={sandwich_rx_rads!r}")
if self.label:
args.append(f"label={self.label!r}")
return f"qss.AceCR({', '.join(args)})"

def __str__(self) -> str:
rads_str = f"{self.rads}"
if np.isclose(round(self.rads / np.pi, 5) * np.pi, self.rads):
rads_str = f"{round(self.rads / np.pi, 5)}π"
if self.sandwich_rx_rads == 0 and self.rads == np.pi / 2:
rads = self.params[0]
rads_str = f"{rads}"
if np.isclose(round(rads / np.pi, ndigits=5) * np.pi, rads):
rads_str = f"{round(rads / np.pi, ndigits=5)}π"
sandwich_rx_rads = 0.0
if len(self.params) > 1:
sandwich_rx_rads = self.params[1]
if sandwich_rx_rads == 0 and rads == np.pi / 2:
return "AceCR"
elif self.sandwich_rx_rads != 0 and self.rads not in [0, np.pi / 2]:
arg = qiskit.circuit.tools.pi_check(self.sandwich_rx_rads, ndigits=8)
elif sandwich_rx_rads != 0 and rads not in [0, np.pi / 2]:
arg = qiskit.circuit.tools.pi_check(sandwich_rx_rads, ndigits=8)
return f"AceCR({rads_str})|RXGate({arg})|"
elif self.sandwich_rx_rads != 0:
arg = qiskit.circuit.tools.pi_check(self.sandwich_rx_rads, ndigits=8)
elif sandwich_rx_rads != 0:
arg = qiskit.circuit.tools.pi_check(sandwich_rx_rads, ndigits=8)
return f"AceCR|RXGate({arg})|"
else:
return f"AceCR({rads_str})"
Expand Down
Loading