Skip to content

Commit

Permalink
add idle gate
Browse files Browse the repository at this point in the history
  • Loading branch information
BoxiLi committed May 9, 2021
1 parent a41a148 commit d58c310
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/qutip_qip/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
iswap, sqrtswap, sqrtiswap, fredkin,
toffoli, controlled_gate, globalphase,
expand_operator, gate_sequence_product)
from qutip import tensor, basis, identity, ket2dm
from qutip import tensor, basis, identity, ket2dm, qeye
from qutip.qobj import Qobj
from qutip.measurement import measurement_statistics

Expand Down Expand Up @@ -750,7 +750,7 @@ def _resolve_to_universal(self, gate, temp_resolved, basis_1q, basis_2q):

def _gate_IGNORED(self, gate, temp_resolved):
temp_resolved.append(gate)
_gate_RY = _gate_RZ = _gate_basis_2q = _gate_IGNORED
_gate_RY = _gate_RZ = _gate_basis_2q = _gate_IDLE = _gate_IGNORED
_gate_CNOT = _gate_RX = _gate_IGNORED

def _gate_SQRTNOT(self, gate, temp_resolved):
Expand Down Expand Up @@ -1258,7 +1258,7 @@ def resolve_gates(self, basis=["CNOT", "RX", "RY", "RZ"]):
num_cbits=self.num_cbits)
temp_resolved = []

basis_1q_valid = ["RX", "RY", "RZ"]
basis_1q_valid = ["RX", "RY", "RZ", "IDLE"]
basis_2q_valid = ["CNOT", "CSIGN", "ISWAP", "SQRTSWAP", "SQRTISWAP"]

num_measurements = len(list(filter(
Expand All @@ -1277,6 +1277,7 @@ def resolve_gates(self, basis=["CNOT", "RX", "RY", "RZ"]):
elif gate in basis_1q_valid:
basis_1q.append(gate)
else:
pass
raise NotImplementedError(
"%s is not a valid basis gate" % gate)
if len(basis_1q) == 1:
Expand Down Expand Up @@ -1550,6 +1551,8 @@ def propagators(self, expand=True):
gate.targets[0]))
elif gate.name == "GLOBALPHASE":
self.U_list.append(globalphase(gate.arg_value, self.N))
elif gate.name == "IDLE":
self.U_list.append(qeye(self.N * [2]))
elif gate.name in self.user_gates:
if gate.controls is not None:
raise ValueError("A user defined gate {} takes only "
Expand Down Expand Up @@ -1655,6 +1658,8 @@ def propagators_no_expand(self):
self.U_list.append(toffoli())
elif gate.name == "GLOBALPHASE":
self.U_list.append(globalphase(gate.arg_value, n))
elif gate.name == "IDLE":
self.U_list.append(qeye(2))
elif gate.name in self.user_gates:
if gate.controls is not None:
raise ValueError("A user defined gate {} takes only "
Expand Down
12 changes: 11 additions & 1 deletion src/qutip_qip/compiler/gatecompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ def __init__(self, num_qubits=None, params=None, pulse_dict=None, N=None):
self.num_qubits = num_qubits or N
self.N = num_qubits # backward compatibility
self.params = params if params is not None else {}
self.gate_compiler = {"GLOBALPHASE": self.globalphase_compiler}
self.gate_compiler = {
"GLOBALPHASE": self.globalphase_compiler,
"IDLE": self.idle_compiler
}
self.args = {}
self.args.update({"params": self.params})
self.global_phase = 0.
Expand All @@ -98,6 +101,13 @@ def globalphase_compiler(self, gate, args):
"""
pass

def idle_compiler(self, gate, args):
"""
Compiler for the GLOBALPHASE gate
"""
idle_time = gate.arg_value
return [Instruction(gate, idle_time, [])]

def compile(
self, circuit, schedule_mode=None, args=None):
"""
Expand Down
1 change: 1 addition & 0 deletions tests/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ def test_numerical_evolution(
circuit.add_gate("ISWAP", targets=[2, 1])
circuit.add_gate("Y", targets=[2])
circuit.add_gate("Z", targets=[0])
circuit.add_gate("IDLE", targets=[1], arg_value=1.)
circuit.add_gate("CNOT", targets=[0], controls=[2])
circuit.add_gate("Z", targets=[1])
circuit.add_gate("X", targets=[1])
Expand Down

0 comments on commit d58c310

Please sign in to comment.