Esempio n. 1
0
batch_size = int(len(tomo_circuits)/nr_batches)
if len(tomo_circuits) % nr_batches != 0:
    nr_batches += 1

for i in range(nr_batches):
    run_circuits = tomo_circuits[i*batch_size:(i+1)*batch_size]
    circuit_list = []
    for cir in run_circuits:
        Q_program.get_circuit(cir).name = cir
        circuit_list.append(Q_program.get_circuit(cir))
    print('Batch %d/%d: %s' % (i+1, nr_batches, 'INITIALIZING'))
    if i == 0:
        job = execute(circuit_list, backend=backendname, shots=shots)
        jobs.append(job)
        job_data.append({'Date': job.creation_date,
                         'Jobid': job.id, 'runtype': run_type, 'batchno': i})
        print('Batch %d/%d: %s' % (i+1, nr_batches, 'SENT'))
    else:
        job = execute(circuit_list, backend=backendname, shots=shots)
        jobs.append(job)
        job_data.append({'Date': job.creation_date,
                         'Jobid': job.id, 'runtype': run_type, 'batchno': i})
        print('Batch %d/%d: %s' % (i+1, nr_batches, 'SENT'))

###############################################################################
store.save_jobids(circuit_name, job_data, tomo_set,
                  backendname, shots, nr_batches, run_type)
store.save_last(circuit_name, job_data, tomo_set,
                backendname, shots, nr_batches, run_type)
# store.save_jobs(circuit_name,run_type,backendname,jobs,tomo_set,shots)
        'Jobid': job.id,
        'runtype': run_type,
        'batchno': i
    })
    print('Batch %d/%d: %s' % (i + 1, nr_batches, 'SENT')
          )  # This batch is done and the jobs are saved to job_data and jobs

###############################################################################
store.save_jobdata(
    circuit_name,
    job_data,
    tomo_set,  # Save the data of all jobs (in job_data) to file
    backendname,
    shots,
    nr_batches,
    run_type,
    Unitary)
store.save_last(
    circuit_name,
    job_data,
    tomo_set,
    backendname,  # Save also to 'last' file
    shots,
    nr_batches,
    run_type,
    Unitary)

unregister(
    provider
)  # Unregister to prevent conflict with other files that register again