Ejemplo n.º 1
0
def generate_full_layer_circuit(n_qubits):
    circuit = QubitCircuit(n_qubits)

    for i in range(int(n_qubits / 2)):
        circuit.cnot(i * 2, (i * 2) + 1)

    return circuit
Ejemplo n.º 2
0
def generate_full_layer_circuit(n_qubits):
    """
    Generates a Circuit object (in our framework) with all pairs interactions

    :param n_qubits: number of qubits
    :return: QubitCircuit, a circuit with all pairs interactions
    """
    circuit = QubitCircuit(n_qubits)

    for i in range(int(n_qubits / 2)):
        circuit.cnot(i * 2, (i * 2) + 1)

    return circuit
Ejemplo n.º 3
0
def generate_completely_random_circuit(n_qubits, n_gates):
    circuit = QubitCircuit(n_qubits)

    for _ in range(n_gates):
        q1 = random.randint(0, n_qubits - 1)
        q2 = random.randint(0, n_qubits - 1)

        while q1 == q2:
            q1 = random.randint(0, n_qubits - 1)
            q2 = random.randint(0, n_qubits - 1)

        circuit.cnot(q1, q2)

    return circuit
Ejemplo n.º 4
0
def generate_multi_layer_circuit(n_qubits, n_layers, layer_density=1.0):
    circuit = QubitCircuit(n_qubits)

    for _ in range(n_layers):
        add_layer(circuit, layer_density)

    return circuit
Ejemplo n.º 5
0
def generate_completely_random_circuit(n_qubits, n_gates):
    """
    Generates a Circuit with random gates

    :param n_qubits: int, number of qubits
    :param n_gates: int, number of random gates to add
    :return: QubitCircuit, randomly connected
    """
    circuit = QubitCircuit(n_qubits)

    for _ in range(n_gates):
        q1 = random.randint(0, n_qubits - 1)
        q2 = random.randint(0, n_qubits - 1)

        while q1 == q2:
            q1 = random.randint(0, n_qubits - 1)
            q2 = random.randint(0, n_qubits - 1)

        circuit.cnot(q1, q2)

    return circuit
Ejemplo n.º 6
0
def generate_multi_layer_circuit(n_qubits, n_layers, layer_density=1.0):
    """
    Generates a random circuit, parametrized by density.

    :param n_qubits: int, number of qubits in the circuit
    :param n_layers: int, number of layers in the circuit
    :param layer_density: float, fraction of interaction pairs which will have gates on it
    :return: QubitCircuit, randomly initialized with n_layers and density gates on
    """
    circuit = QubitCircuit(n_qubits)

    for _ in range(n_layers):
        add_layer(circuit, layer_density)

    return circuit
def import_test_set():
    print('Importing test set...')

    directory_path = "./realistic_test_set/"

    files = os.listdir(directory_path)
    qasm_files = list(filter(lambda file_name: len(file_name) > 5 and file_name[-5:] == ".qasm", files))

    circuits = []

    for i,file_name in enumerate(qasm_files):
        file_path = directory_path + file_name

        if os.path.getsize(file_path) > 10000:
            continue

        qiskit_circuit = QuantumCircuit.from_qasm_file(file_path)

        gates = []

        for gate_obj, qubits, _ in qiskit_circuit.data:
            if len(qubits) > 1:
                if gate_obj.__class__.__name__ not in  ["CnotGate", "CXGate"]:
                    exit("Non-cnot gate (" + gate_obj.__class__.__name__ + ") found for circuit: " + str(file_name))

                gate = (qubits[0].index, qubits[1].index)
                gates.append(gate)

        circuit = QubitCircuit.from_gates(16, gates)

        circuits.append(circuit)

        if i % int(len(qasm_files) / 10) == 0:
            print('Import ' + str(int(100 * i / len(qasm_files))) + '% complete')

    return list(filter(lambda c: c.depth() < 200, circuits))