예제 #1
0
            def synthesizer(boolean_expression):
                from tweedledum.synthesis import pkrm_synth
                from qiskit.circuit.classicalfunction.utils import tweedledum2qiskit

                truth_table = boolean_expression._tweedledum_bool_expression.truth_table(
                    output_bit=0
                )
                tweedledum_circuit = pkrm_synth(truth_table, {"pkrm_synth": {"phase_esop": True}})
                return tweedledum2qiskit(tweedledum_circuit)
    def test_x(self):
        """Single uncontrolled X"""
        tweedledum_circuit = {'num_qubits': 1, 'gates': [{'gate': 'X', 'qubits': [0]}]}
        circuit = tweedledum2qiskit(tweedledum_circuit)

        expected = QuantumCircuit(1)
        expected.x(0)

        self.assertEqual(circuit, expected)
예제 #3
0
    def test_x(self):
        """Single uncontrolled X"""
        tweedledum_circuit = Circuit()
        tweedledum_circuit.apply_operator(X(), [tweedledum_circuit.create_qubit()])

        circuit = tweedledum2qiskit(tweedledum_circuit)

        expected = QuantumCircuit(1)
        expected.x(0)

        self.assertEqual(circuit, expected)
    def test_cx_1_0(self):
        """CX(1, 0)"""
        tweedledum_circuit = {'num_qubits': 2, 'gates': [{'gate': 'X',
                                                          'qubits': [0],
                                                          'control_qubits': [1],
                                                          'control_state': '1'}]}
        circuit = tweedledum2qiskit(tweedledum_circuit)

        expected = QuantumCircuit(2)
        expected.append(XGate().control(1, ctrl_state='1'), [1, 0])

        self.assertEqual(expected, circuit)
    def test_cx_qreg(self):
        """CX(0, 1) with qregs parameter"""
        qr = QuantumRegister(2, 'qr')
        tweedledum_circuit = {'num_qubits': 2, 'gates': [{'gate': 'X',
                                                          'qubits': [0],
                                                          'control_qubits': [1],
                                                          'control_state': '1'}]}
        circuit = tweedledum2qiskit(tweedledum_circuit, qregs=[qr])

        expected = QuantumCircuit(qr)
        expected.append(XGate().control(1, ctrl_state='1'), [qr[1], qr[0]])

        self.assertEqual(expected, circuit)
    def test_cx_1_0(self):
        """CX(1, 0)"""
        tweedledum_circuit = Circuit()
        qubits = list()
        qubits.append(tweedledum_circuit.create_qubit())
        qubits.append(tweedledum_circuit.create_qubit())
        tweedledum_circuit.apply_operator(X(), [qubits[1], qubits[0]])

        circuit = tweedledum2qiskit(tweedledum_circuit)

        expected = QuantumCircuit(2)
        expected.append(XGate().control(1, ctrl_state="1"), [1, 0])

        self.assertEqual(expected, circuit)
    def test_cx_0_1(self):
        """CX(0, 1)"""
        tweedledum_circuit = Circuit()
        qubits = list()
        qubits.append(tweedledum_circuit.create_qubit())
        qubits.append(tweedledum_circuit.create_qubit())
        tweedledum_circuit.apply_operator(X(), [qubits[0], qubits[1]])

        circuit = tweedledum2qiskit(tweedledum_circuit)

        expected = QuantumCircuit(2)
        expected.append(XGate().control(1, ctrl_state='1'), [0, 1])

        self.assertEqual(circuit, expected)
    def test_cx_qreg(self):
        """CX(0, 1) with qregs parameter"""
        tweedledum_circuit = Circuit()
        qubits = list()
        qubits.append(tweedledum_circuit.create_qubit())
        qubits.append(tweedledum_circuit.create_qubit())
        tweedledum_circuit.apply_operator(X(), [qubits[1], qubits[0]])

        qr = QuantumRegister(2, "qr")
        circuit = tweedledum2qiskit(tweedledum_circuit, qregs=[qr])

        expected = QuantumCircuit(qr)
        expected.append(XGate().control(1, ctrl_state="1"), [qr[1], qr[0]])

        self.assertEqual(expected, circuit)