Пример #1
0
    prog.swap(input_qubit[1], input_qubit[0])  # number=2
    prog.swap(input_qubit[1], input_qubit[0])  # number=3
    prog.cx(input_qubit[1], input_qubit[0])  # number=4
    prog.cx(input_qubit[1], input_qubit[0])  # number=5
    # 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
    IBMQ.load_account()
    provider = IBMQ.get_provider(hub='ibm-q')
    provider.backends()
    backend = provider.get_backend("ibmq_belem")

    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_QC53.csv", "w")
    print(info, file=writefile)
import numpy as np
import qiskit.pulse.library as pulse_lib
import qiskit.pulse as pulse
from qiskit.pulse.macros import measure_all
from qiskit.compiler import assemble
from qiskit.tools import job_monitor
from qiskit import IBMQ
import matplotlib.pyplot as plt
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
from sklearn.model_selection import train_test_split
import pickle

provider = IBMQ.load_account()
backend = provider.get_backend("ibmq_armonk")


def get_pi_pulse_01(c):
    return pulse_lib.gaussian(duration=c["drive_samples"],
                              amp=c["pi_amp_01"],
                              sigma=c["drive_sigma"],
                              name="pi_pulse_01")


def get_pi_pulse_12(c):
    pulse = pulse_lib.gaussian(duration=c["drive_samples"],
                               amp=c["pi_amp_12"],
                               sigma=c["drive_sigma"],
                               name="pi_pulse_12")
    t_samples = np.linspace(0, c["dt"] * c["drive_samples"],
                            c["drive_samples"])
    sine_pulse = np.sin(2 * np.pi *
Пример #3
0
import matplotlib.pyplot as plt
from qiskit import BasicAer, Aer, QuantumCircuit, QuantumRegister, ClassicalRegister, execute, IBMQ
from qiskit.visualization import *
from qiskit.tools.monitor import job_monitor
import math

#########################################################
#########################################################
# #INIT

qasm = Aer.get_backend('qasm_simulator')
IBMQ.load_account()  # Init Real Quantum computeur
provider = IBMQ.get_provider('ibm-q')
quantum_computer = provider.get_backend('ibmq_burlington')

backend_sim = qasm  # Choose your backend : <quantom_computer> or <qasm>

statevector_sim = Aer.get_backend("statevector_simulator")

ship = ["petit", "moyen", "grand"]

nb_qubits = len(ship)
qubits = [1, 2, 3, 4, 5]
fake_qubit = 5 - nb_qubits
play = True

#########################################################
#########################################################
# #Circuit

# Quantum Circuit
Пример #4
0
def optimise():
    '''Method used to optimise the error rate parameters. All the results are shown while the method
    is run. Please allow ample time for the GA optimisation to succeed.'''
    # Required variables
    provider = IBMQ.load_account() # Loads the IBMQ account
    device = provider.get_backend('ibmq_16_melbourne') # Prefered device
    backend = Aer.get_backend("qasm_simulator") # The simulator
    iterations = 1000 # Iterations should remain constant to ensure consistency

    # Run the combined quantum noise simulator and get the distribution pre-optimization
    # Getting the noise data
    path_data = "/Users/b6035076/Qiskit/qiskit-tutorials-master/PhD Research/Unified Noise Model/Data/ibmq_16_melbourne_calibrations.csv" # Import the path where the noise data are stored
    data = machineData(path_data)
    graph = [[0,1], [1,2], [2,3], [3,4], [4,5], [5,6], [4,10], [5,9], [6,8], [8,7]] # The two-qubit gates that we are interested in
    gates = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] # The single-qubit gates that we are interested in

    sqRates = getSingleQubitErrorRates(data) # Dictionary containing the single qubit error rates
    tqRates = getTwoQubitErrorRates(data) # Dictionary containing the two qubit error rates
    measRates = getMeasureErrorRates(data) # Dictionary containing the measurement error rates per qubit
    T1s,T2s = getDecoherenceTimes(data)

    circ = qwQASM()
    nfcirc = noiseFreeqwQASM()

    # Run simulations with the UNM
    start_time = time.time()
    counts_comb = qwNoiseExecute(iterations, thermal = True, backend = device, T1s = T1s, T2s = T2s, graph = graph, gates = gates)
    end_time = time.time()
    print("\nTime elapsed:", end_time - start_time, "seconds.")
    counts_comb = getCounts(counts_comb, iterations)
    counts_comb = dict(OrderedDict(sorted(counts_comb.items())))
    print("\nCounts on noisy quantum simulator:", counts_comb)

    # Calculate the HD pre-optimization
    avgExData = {'0000': 232, '0001': 111, '0010': 101, '0011': 54, '0100': 102, '0101': 62, '0110': 78, '0111': 48, '1000': 24, '1001': 19, '1010': 33, '1011': 32, '1100': 25, '1101': 27, '1110': 24, '1111': 28} # The averaged distribution from the Quantum Computer
    
    # Get the probabilities of the **ordered** dictionaries
    p = getProbabilities(counts_comb, iterations)
    q = getProbabilities(avgExData, iterations)

    # Calculate the HD
    h_pre = hellingerDistance(p,q)
    print("The HD between the UNM and the Quantum Computer for", iterations, "iterations is:", h_pre)

   # Prepare for the GA optimization
    q_pairs = [(0,1), (1,2), (2,3), (3,4), (4,5)] # List of qubit pairs in ibmq_16_melbourne
    s_q = [0, 1, 2, 3, 4, 5] # The qubits themselves
    m_q = [1, 2, 0] # The qubits being measured
    num_q = len(s_q) # Number of qubits in the system
    num_rates = 25 # Number of parameters for optimization
    scalar = 1000000 # Scalar used to eliminate floating point in the encoded parameters binary representation
    thermal = True # Decide whether we want the thermal relaxation channel or not.

    # Get the error rates relevant to our system as dictionaries and lists
    sqRatesDct,tqRatesDct,measRatesDct = getSubsystemRates(q_pairs, num_q, s_q, m_q, data)

    print("Single-qubit rates with qubit information:", sqRatesDct)
    print("Two-qubit rates with qubit information::", tqRatesDct)
    print("Measurement rates with qubit information::", measRatesDct, "\n")

    sqRates = list(sqRatesDct.values())
    tqRates = list(tqRatesDct.values()) # Use set to remove duplicates
    measRates = list(measRatesDct.values())
    print("Single-qubit rates:", sqRates)
    print("Two-qubit rates:", tqRates)
    print("Measurement rates:", measRates, "\n")

    # Encode the parameters to get the chromosome bit-string
    chromosome = paramEncoding(scalar, sqRates, tqRates, measRates)
    init_chrom = decode(initChrom(chromosome), scalar, 14, num_q)
    print("Initial chromosome:", init_chrom, end = '\n')
    print("\n")

    # Evaluate the initial Hellinger distance
    init_fitness = hd_evaluate(initChrom(chromosome))
    
    # Run the Genetic Algorithm Optimization
    population_size = 16 # The number of solutions generated every time
    num_generations = 50 # The number of generations, i.e how many times the populations will reproduce
    gene_length = len(chromosome)

    bestRates = runGA(population_size, num_generations, gene_length, scalar, chromosome, num_rates, num_q)
    print("The optimized error rates are:", bestRates)
    
    # Calculate the post-optimization HD
    # Run simulations with the UNM
    start_time = time.time()
    post_counts = combinedExecute(iterations, thermal = True, ratesList = bestRates, backend = device, T1s = T1s, T2s = T2s, graph = graph, gates = gates)
    end_time = time.time()
    print("\nTime elapsed:", end_time - start_time, "seconds.")
    post_counts = getCounts(post_counts, iterations)
    post_counts = dict(OrderedDict(sorted(post_counts.items())))
    print("\nCounts on noisy quantum simulator:", post_counts)

    # Get the probabilities of the **ordered** dictionaries
    p = getProbabilities(post_counts, iterations)
    q = getProbabilities(avgExData, iterations)

    # Calculate the HD
    h_post = hellingerDistance(p,q)
    print("The HD between the UNM and the Quantum Computer post-optimization for", iterations, "iterations is:", h_post)
    
    return None