def test_inverse_and_append(self): """test appending inverted gates to circuits""" q = QuantumRegister(1) circ = QuantumCircuit(q, name='circ') circ.s(q) circ.append(SGate().inverse(), q[:]) circ.append(TGate().inverse(), q[:]) circ.t(q) gate = circ.to_instruction() circ = QuantumCircuit(q, name='circ') circ.inverse() circ.tdg(q) circ.t(q) circ.s(q) circ.sdg(q) gate_inverse = circ.to_instruction() self.assertEqual(gate.inverse().definition, gate_inverse.definition)
def _define(self): """ gate xx_minus_yy(theta, beta) a, b { rz(-beta) b; rz(-pi/2) a; sx a; rz(pi/2) a; s b; cx a, b; ry(theta/2) a; ry(-theta/2) b; cx a, b; sdg b; rz(-pi/2) a; sxdg a; rz(pi/2) a; rz(beta) b; } """ theta, beta = self.params register = QuantumRegister(2, "q") circuit = QuantumCircuit(register, name=self.name) a, b = register rules = [ (RZGate(-beta), [b], []), (RZGate(-pi / 2), [a], []), (SXGate(), [a], []), (RZGate(pi / 2), [a], []), (SGate(), [b], []), (CXGate(), [a, b], []), (RYGate(theta / 2), [a], []), (RYGate(-theta / 2), [b], []), (CXGate(), [a, b], []), (SdgGate(), [b], []), (RZGate(-pi / 2), [a], []), (SXdgGate(), [a], []), (RZGate(pi / 2), [a], []), (RZGate(beta), [b], []), ] for instr, qargs, cargs in rules: circuit._append(instr, qargs, cargs) self.definition = circuit
def _define_from_label(self): q = QuantumRegister(self.num_qubits, "q") initialize_circuit = QuantumCircuit(q, name="init_def") for qubit, param in enumerate(reversed(self.params)): initialize_circuit.append(Reset(), [q[qubit]]) if param == "1": initialize_circuit.append(XGate(), [q[qubit]]) elif param == "+": initialize_circuit.append(HGate(), [q[qubit]]) elif param == "-": initialize_circuit.append(XGate(), [q[qubit]]) initialize_circuit.append(HGate(), [q[qubit]]) elif param == "r": # |+i> initialize_circuit.append(HGate(), [q[qubit]]) initialize_circuit.append(SGate(), [q[qubit]]) elif param == "l": # |-i> initialize_circuit.append(HGate(), [q[qubit]]) initialize_circuit.append(SdgGate(), [q[qubit]]) return initialize_circuit
def _define_from_label(self): q = QuantumRegister(self.num_qubits, 'q') initialize_circuit = QuantumCircuit(q, name='init_def') for qubit, param in enumerate(reversed(self.params)): initialize_circuit.append(Reset(), [q[qubit]]) if param == '1': initialize_circuit.append(XGate(), [q[qubit]]) elif param == '+': initialize_circuit.append(HGate(), [q[qubit]]) elif param == '-': initialize_circuit.append(XGate(), [q[qubit]]) initialize_circuit.append(HGate(), [q[qubit]]) elif param == 'r': # |+i> initialize_circuit.append(HGate(), [q[qubit]]) initialize_circuit.append(SGate(), [q[qubit]]) elif param == 'l': # |-i> initialize_circuit.append(HGate(), [q[qubit]]) initialize_circuit.append(SdgGate(), [q[qubit]]) return initialize_circuit