Esempio n. 1
0
 def _cz(self):
     # cx
     circuit = QuantumCircuit(2)
     circuit.h(1)
     circuit.cz(0, 1)
     circuit.h(1)
     self.add_equivalence(Gates.CXGate(), circuit)
def qiskit_custom_unroll():
    qr = QuantumRegister(5)
    cr = ClassicalRegister(5)
    qiskit_circuit = QuantumCircuit(qr, cr)
    """standard qiskit gates """
    gate = qiskit_gates.CXGate()
    qiskit_circuit.append(gate, qargs=[3, 2])
    gate = qiskit_gates.CZGate()
    qiskit_circuit.append(gate, qargs=[1, 2])
    gate = qiskit_gates.HGate()
    qiskit_circuit.append(gate, qargs=[1])
    gate = qiskit_gates.CCXGate()
    qiskit_circuit.append(gate, qargs=[0, 1, 2])
    gate = qiskit_gates.RXGate(np.pi / 4)
    qiskit_circuit.append(gate, qargs=[0])
    """custom gate"""
    # custom_matrix1 = np.array([
    #     [np.e**(1j*np.pi/2), 0, 0, 0],
    #     [0, 1, 0, 0],
    #     [0, 0, 1, 0],
    #     [0, 0, 0, np.e**(1j*np.pi/2)]
    # ], dtype=complex)
    # custom_matrix1 = random_unitary(4, seed=42)
    # custom_gate1 = UnitaryGate(custom_matrix1, label="unitary_custom")
    # qiskit_circuit.append(custom_gate1, qargs=[0,1])
    """custom gate #2"""
    custom_matrix1 = random_unitary(4, seed=42)
    custom_gate1 = UnitaryGate(custom_matrix1, label="unitary_2qubits")
    qiskit_circuit.append(custom_gate1, qargs=[0, 1])
    """custom gate #3"""
    # custom_matrix1 = random_unitary(8, seed=42)
    # custom_gate1 = UnitaryGate(custom_matrix1, label="unitary_3qubits")
    # qiskit_circuit.append(custom_gate1, qargs=[0,1,2])
    """custom gate #4"""
    # operator = Operator([[1, 0, 0, 0],
    #           [0, 0, 0, 1],
    #           [0, 0, 1, 0],
    #           [0, 1, 0, 0]])
    # custom_gate1 = UnitaryGate(custom_matrix1, label="operator")
    # qiskit_circuit.unitary(operator, [0,1], label="operator")
    """parameterized qiskit cirucit"""
    # theta = qiskit_circuit_library.Parameter("θ")
    # qiskit_circuit.rz(theta, 1)

    # show_figure(qiskit_circuit)
    return qiskit_circuit
Esempio n. 3
0
    elif gate == 'rz':
        gc = gates.RZGate
    elif gate == 'id':
        gc = gates.IGate
    elif gate == 'sx':
        gc = gates.SXGate
    elif gate == 'x':
        gc = gates.XGate
    else:
        raise QiskitError('Gate is not a valid basis gate for this simulator: %s' % gate)

    return gc(*params).to_matrix()


# Cache CX matrix as no parameters.
_CX_MATRIX = gates.CXGate().to_matrix()


def cx_gate_matrix():
    """Get the matrix for a controlled-NOT gate."""
    return np.array([[1, 0, 0, 0],
                     [0, 0, 0, 1],
                     [0, 0, 1, 0],
                     [0, 1, 0, 0]], dtype=complex)


def einsum_matmul_index(gate_indices, number_of_qubits):
    """Return the index string for Numpy.einsum matrix-matrix multiplication.

    The returned indices are to perform a matrix multiplication A.B where
    the matrix A is an M-qubit matrix, matrix B is an N-qubit matrix, and
Esempio n. 4
0
         "g": qiskit.TdgGate
     },
     "pyquil": {
         "r": pyquil_replacement.tdg_replacement
     },
     "matrix": qiskit.TdgGate().to_matrix()
 },
 # multi
 "CX": {
     "qiskit": {
         "g": qiskit.CXGate
     },
     "pyquil": {
         "g": pyquil.CNOT
     },
     "matrix": qiskit.CXGate().to_matrix()
 },
 # CZ matrix not defined in qiskit
 "CZ": {
     "qiskit": {
         "g": qiskit.CZGate
     },
     "pyquil": {
         "g": pyquil.CZ
     },
     "matrix":
     np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, -1]],
              dtype=complex)
 },
 "CCX": {
     "qiskit": {