示例#1
0
    prog.z(input_qubit[1])  # number=9
    prog.cx(input_qubit[1], input_qubit[0])  # number=10
    # circuit end
    return prog


if __name__ == '__main__':
    n = 2
    f = lambda rep: rep[-1]
    # f = lambda rep: "1" if rep[0:2] == "01" or rep[0:2] == "10" else "0"
    # f = lambda rep: "0"
    prog = make_circuit(n, f)
    sample_shot = 2800
    backend = BasicAer.get_backend('qasm_simulator')

    circuit1 = transpile(prog, FakeVigo())
    circuit1.x(qubit=3)
    circuit1.x(qubit=3)
    circuit1.measure_all()
    prog = circuit1

    info = execute(prog, backend=backend,
                   shots=sample_shot).result().get_counts()

    writefile = open("../data/startQiskit239.csv", "w")
    print(info, file=writefile)
    print("results end", file=writefile)
    print(circuit1.depth(), file=writefile)
    print(circuit1, file=writefile)
    writefile.close()
示例#2
0
    prog.x(input_qubit[1]) # number=2
    prog.x(input_qubit[1]) # number=3
    # circuit end
    return prog




if __name__ == '__main__':
    n = 2
    f = lambda rep: rep[-1]
    # f = lambda rep: "1" if rep[0:2] == "01" or rep[0:2] == "10" else "0"
    # f = lambda rep: "0"
    prog = make_circuit(n, f)
    sample_shot =2800
    backend = FakeVigo()

    circuit1 = transpile(prog,FakeVigo())
    circuit1.x(qubit=3)
    circuit1.x(qubit=3)
    circuit1.measure_all()
    prog = circuit1


    info = execute(prog, backend=backend, shots=sample_shot).result().get_counts()

    writefile = open("../data/startQiskit_noisy11.csv","w")
    print(info,file=writefile)
    print("results end", file=writefile)
    print(circuit1.depth(),file=writefile)
    print(circuit1,file=writefile)
示例#3
0
        prog.measure(input_qubit[i], classical[i])

    return prog


if __name__ == '__main__':
    a = "111"
    b = "0"
    f = lambda rep: bitwise_xor(bitwise_dot(a, rep), b)
    prog = make_circuit(4, f)
    IBMQ.load_account()
    provider = IBMQ.get_provider(hub='ibm-q')
    provider.backends()
    backend = least_busy(
        provider.backends(
            filters=lambda x: x.configuration().n_qubits >= 2 and not x.
            configuration().simulator and x.status().operational == True))
    sample_shot = 8000

    info = execute(prog, backend=backend,
                   shots=sample_shot).result().get_counts()
    backend = FakeVigo()
    circuit1 = transpile(prog, backend, optimization_level=2)

    writefile = open("../data/startQiskit_QC2722.csv", "w")
    print(info, file=writefile)
    print("results end", file=writefile)
    print(circuit1.__len__(), file=writefile)
    print(circuit1, file=writefile)
    writefile.close()
class TestBackendOverview(QiskitTestCase):
    """Tools test case."""
    def _restore_ibmq(self):
        if not self.import_error:
            qiskit.IBMQ = self.ibmq_back
        else:
            del qiskit.IBMQ
        if self.prov_backup:
            providers.ibmq = self.prov_backup
        else:
            del providers.ibmq

    def _restore_ibmq_mod(self):
        if self.ibmq_module_backup is not None:
            sys.modules['qiskit.providers.ibmq'] = self.ibmq_module_backup
        else:
            sys.modules.pop('qiskit.providers.ibmq')

    def setUp(self):
        super().setUp()
        ibmq_mock = MagicMock()
        ibmq_mock.IBMQBackend = FakeBackend
        if 'qiskit.providers.ibmq' in sys.modules:
            self.ibmq_module_backup = sys.modules['qiskit.providers.ibmq']
        else:
            self.ibmq_module_backup = None
        sys.modules['qiskit.providers.ibmq'] = ibmq_mock
        self.addCleanup(self._restore_ibmq_mod)

        if hasattr(qiskit, 'IBMQ'):
            self.import_error = False
        else:
            self.import_error = True
            qiskit.IBMQ = None
        self.ibmq_back = qiskit.IBMQ
        qiskit.IBMQ = FakeProviderFactory()
        self.addCleanup(self._restore_ibmq)
        if hasattr(providers, 'ibmq'):
            self.prov_backup = providers.ibmq
        else:
            self.prov_backup = None
        providers.ibmq = MagicMock()

    @patch('qiskit.tools.monitor.overview.get_unique_backends',
           return_value=[FakeVigo()])
    def test_backend_overview(self, _):
        """Test backend_overview"""
        with patch('sys.stdout', new=StringIO()) as fake_stdout:
            backend_overview()
        stdout = fake_stdout.getvalue()
        self.assertIn('Operational:', stdout)
        self.assertIn('Avg. T1:', stdout)
        self.assertIn('Num. Qubits:', stdout)

    @patch('qiskit.tools.monitor.overview.get_unique_backends',
           return_value=[FakeVigo()])
    def test_backend_monitor(self, _):
        """Test backend_monitor"""
        for back in [FakeVigo()]:
            if not back.configuration().simulator:
                backend = back
                break
        with patch('sys.stdout', new=StringIO()) as fake_stdout:
            backend_monitor(backend)

        stdout = fake_stdout.getvalue()
        self.assertIn('Configuration', stdout)
        self.assertIn('Qubits [Name / Freq / T1 / T2 / ', stdout)
        for gate in backend.properties().gates:
            if gate.gate not in ['id'] and len(gate.qubits) == 1:
                self.assertIn(gate.gate.upper() + ' err', stdout)
        self.assertIn('Readout err', stdout)
        self.assertIn('Multi-Qubit Gates [Name / Type / Gate Error]', stdout)