<jupyter_start><jupyter_text>Quantum Inspire performance testWe compare performance of the simulator with the circuit from "Overview and Comparison of Gate Level Quantum Software Platforms", https://arxiv.org/abs/1807.02500  Define the circuit<jupyter_code>import time
import os
import numpy as np
from getpass import getpass
from IPython.display import display

from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister, execute
from qiskit.tools.visualization import plot_histogram, circuit_drawer

from quantuminspire.credentials import load_account, get_token_authentication, get_basic_authentication
from quantuminspire.qiskit import QI

QI_EMAIL = os.getenv('QI_EMAIL')
QI_PASSWORD = <PASSWORD>('QI_PASSWORD')
QI_URL = os.getenv('API_URL', 'https://api.quantum-inspire.com/')
def format_vector(state_vector, decimal_precision=7):
    """ Format the state vector into a LaTeX formatted string.

    Args:
        state_vector (list or array): The state vector with complex
                                      values e.g. [-1, 2j+1].

    Returns:
        str: The LaTeX format.
    """
    result = []
    epsilon = 1/pow(10, decimal_precision)
    bit_length = (len(state_vector) - 1).bit_length()
    for index, complex_value in enumerate(state_vector):
        has_imag_part = np.round(complex_value.imag, decimal_precision) != 0.0
        value = complex_value if has_imag_part else complex_value.real
        value_round = np.round(value, decimal_precision)
        if np.abs(value_round) < epsilon:
            continue

        binary_state = '{0:0{1}b}'.format(index, bit_length)
        result.append(r'{0:+2g}\left\lvert {1}\right\rangle '.format(value_round, binary_state))
    return ''.join(result)<jupyter_output><empty_output><jupyter_text>We define the circuit based on the number of qubits and the depth (e.g. the number of iterations of the unit building block).<jupyter_code>def pcircuit(nqubits, depth = 10):
    """ Circuit to test performance of quantum computer """
    q = QuantumRegister(nqubits)
    ans = ClassicalRegister(nqubits)
    qc = QuantumCircuit(q, ans)

    for level in range(depth):
        for qidx in range(nqubits):
            qc.h( q[qidx] )
        qc.barrier()
        for qidx in range(nqubits):
            qc.rx(np.pi/2, q[qidx])
        qc.barrier()
            
        for qidx in range(nqubits):
            if qidx!=0:
                qc.cx(q[qidx], q[0])
    for qidx in range(nqubits):
        qc.measure(q[qidx], ans[qidx])
    return q, qc

q,qc = pcircuit(4, 1)
qc.draw(output='mpl')<jupyter_output><empty_output><jupyter_text>Run the cirquit on the Quantum Inspire simulator First we make a connection to the Quantum Inspire website.<jupyter_code>token = load_account()
if token is not None:
    authentication = get_token_authentication(token)
else:
    if QI_EMAIL is None or QI_PASSWORD is None:
        print('Enter email')
        email = input()
        print('Enter password')
        password = <PASSWORD>()
    else:
        email, password = QI_EMAIL, QI_PASSWORD
    authentication = get_basic_authentication(email, password)

QI.set_authentication(authentication, QI_URL)<jupyter_output><empty_output><jupyter_text>We create a QisKit backend for the Quantum Inspire interface and execute the circuit generated above.<jupyter_code>qi_backend = QI.get_backend('QX single-node simulator')  
job = execute(qc, qi_backend)<jupyter_output><empty_output><jupyter_text>We can wait for the results and then print them<jupyter_code>result = job.result()
print('Generated histogram:')
print(result.get_counts())<jupyter_output>Generated histogram:
{'0000': 69, '0001': 64, '0010': 65, '0011': 71, '0100': 61, '0101': 73, '0110': 63, '0111': 66, '1000': 60, '1001': 54, '1010': 59, '1011': 71, '1100': 57, '1101': 75, '1110': 54, '1111': 62}<jupyter_text>Visualization can be done with the normal Python plotting routines, or with the QisKit SDK.<jupyter_code>plot_histogram(result.get_counts(qc))<jupyter_output><empty_output><jupyter_text>To compare we will run the circuit with 20 qubits and depth 20. This takes:* QisKit: 3.7 seconds* ProjectQ: 2.0 seconds Our simulator runs for multiple shots (unless full state projection is used). More details will follow later.<jupyter_code>q, qc = pcircuit(10, 10)
start_time = time.time()

job = execute(qc, qi_backend, shots=8)
job.result()
interval = time.time() - start_time

print('time needed: %.1f [s]' % (interval,))<jupyter_output>time needed: 2.4 [s]
{'fraction_non_alphanumeric': 0.10905441570026762, 'fraction_numerical': 0.032114183764495985, 'mean_word_length': 4.085034013605442, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 29, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '106294', 'license': 'Apache-2.0', 'n_tokens_mistral': 1598, 'n_tokens_neox': 1420, 'n_words': 408, 'path': 'docs/qi-performance-test.ipynb', 'repo_name': 'sergivandenberg/Final-Project', 'size': '4480'}