Ejemplo n.º 1
0
    def test_iadd_overload(self):
        """Test the overloaded + operator."""
        num_qubits, depth = 2, 2

        # construct two circuits for adding
        first_circuit = random_circuit(num_qubits, depth, seed=4242)
        circuit = random_circuit(num_qubits, depth, seed=4242)

        # get a reference
        reference = first_circuit + circuit

        # convert the object to be appended to different types
        others = [
            circuit,
            circuit.to_instruction(),
            circuit.to_gate(),
            NLocal(circuit)
        ]

        # try adding each type
        for other in others:
            nlocal = NLocal(num_qubits,
                            entanglement_blocks=first_circuit,
                            reps=1)
            nlocal += other
            with self.subTest(msg="type: {}".format(type(other))):
                self.assertCircuitEqual(nlocal, reference)
Ejemplo n.º 2
0
    def test_add_nlocal(self, num_qubits):
        """Test adding an nlocal to an nlocal (using add_layer)."""
        # fixed depth of 3 gates per circuit
        depth = 3

        # keep track of a reference circuit
        reference = QuantumCircuit(max(num_qubits))

        # construct the NLocal from the first circuit
        first_circuit = random_circuit(num_qubits[0], depth, seed=4220)
        # TODO Terra bug: if this is to_gate it fails, since the QC adds an instruction not gate
        nlocal = NLocal(max(num_qubits),
                        entanglement_blocks=first_circuit.to_instruction(),
                        reps=1)
        nlocal2 = nlocal.copy()
        _ = nlocal2.data
        reference.append(first_circuit, list(range(num_qubits[0])))

        # append the rest
        for num in num_qubits[1:]:
            circuit = random_circuit(num, depth, seed=4220)
            layer = NLocal(num, entanglement_blocks=circuit, reps=1)
            nlocal.add_layer(layer)
            nlocal2.add_layer(layer)
            reference.append(circuit, list(range(num)))

        self.assertCircuitEqual(nlocal, reference)
        self.assertCircuitEqual(nlocal2, reference)
Ejemplo n.º 3
0
    def test_append_circuit(self, num_qubits):
        """Test appending circuits to an nlocal works normally."""
        # fixed depth of 3 gates per circuit
        depth = 3

        # keep track of a reference circuit
        reference = QuantumCircuit(max(num_qubits))

        # construct the NLocal from the first circuit
        first_circuit = random_circuit(num_qubits[0], depth, seed=4200)
        # TODO Terra bug: if this is to_gate it fails, since the QC adds an instruction not gate
        nlocal = NLocal(max(num_qubits), entanglement_blocks=first_circuit.to_instruction(), reps=1)
        reference.append(first_circuit, list(range(num_qubits[0])))

        # append the rest
        for num in num_qubits[1:]:
            circuit = random_circuit(num, depth, seed=4200)
            nlocal.append(circuit, list(range(num)))
            reference.append(circuit, list(range(num)))

        self.assertCircuitEqual(nlocal, reference)
Ejemplo n.º 4
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created Nov 2020

@author: hassi
"""

# For this simple recipe we will only need the random_circuit method
from qiskit.circuit.random.utils import random_circuit

print("Ch 3: Moving between worlds 2")
print("-----------------------------")

# First we create and print a random quantum circuit
print("Random quantum circuit")
print("----------------------\n")
circ = random_circuit(2, 2, measure=True)
print(circ)

# Next, we export the circuit as QASM code. If you include a filename you can also save the QASM code as a text file on your local machine
print("\nOpenQASM code")
print("-------------\n")

circ.qasm(formatted=True, filename="Circuit.qasm")
Ejemplo n.º 5
0
import json
import time
'''
Python script that sends requests to the api, starts them and retrieves the results
'''

url_creation = "http://localhost:5000/tasks"
url_task = "http://localhost:5000/tasks/"

headers = {'Content-Type': 'application/json'}

tasks = []
circuits = []
for i in range(100):
    circuits.append({
        "qasm": random_circuit(5, 5, 2, measure=True).qasm(),
        "config": {
            "quantum_resource_mapper": {
                "backend_chooser": {
                    "allow_simulator": True
                },
                "execution_types": {
                    "raw": False
                }
            }
        }
    })

print("Send request")
response = requests.request("POST",
                            url_creation,
Ejemplo n.º 6
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# For this simple recipe we will only need the QuantumCircuit method
from qiskit.circuit.random.utils import random_circuit

print("Ch 3: Moving between worlds 2")
print("-----------------------------")

# First we create and print a random quantum circuit
print("Random quantum circuit")
print("----------------------\n")
circ = random_circuit(5, 5, measure=True)
print(circ)

# Next, we export the circuit as QASM code. If you include a filename you can also save the QASM code as a text file on your local machine
print("\nOpenQASM code")
print("-------------\n")

circ.qasm(formatted=True, filename="Circuit.qasm")