def get_h2o_circuits_to_compile():
    set_seeds()

    circuit = get_uccsd_circuit('H2O')
    circuit = optimize_circuit(circuit)
    coupling_list = get_nearest_neighbor_coupling_list(2, 5)
    circuit = optimize_circuit(circuit, coupling_list)

    # layout is 0 2 4 6 8
    #           1 3 5 7 9

    class Blocking1(object):
        blocks = [{0, 1, 2, 3}, {4, 5, 6, 7}, {8, 9}]
        connected_qubit_pairs_list = [[(0, 1), (1, 3), (2, 3), (0, 2)],
                                      [(0, 1), (1, 3), (2, 3), (0, 2)],
                                      [(0, 1)]]

    class Blocking2(object):
        blocks = [{0, 1}, {2, 3, 4, 5}, {6, 7, 8, 9}]
        connected_qubit_pairs_list = [[(0, 1)], [(0, 1), (1, 3), (2, 3),
                                                 (0, 2)],
                                      [(0, 1), (1, 3), (2, 3), (0, 2)]]

    blockings = [Blocking1, Blocking2]

    slice_circuits_list = _get_slice_circuits_list(circuit, blockings)
    return _get_circuits_to_compile(slice_circuits_list)
Exemple #2
0
def _get_qaoa_circuits_to_compile(graph_type,
                                  graph_N,
                                  graph_p,
                                  blockings,
                                  sampling_rate=None):
    assert graph_p in [1, 2, 3, 4, 5, 6, 7, 8], 'we only did p = 1...8'
    set_seeds()
    circuit = get_qaoa_circuit(graph_N, graph_p, graph_type)
    circuit = optimize_circuit(circuit)
    coupling_list = get_nearest_neighbor_coupling_list(2, int(graph_N / 2))
    circuit = optimize_circuit(circuit, coupling_list)
    slice_circuits_list = _get_slice_circuits_list(circuit, blockings)
    return _get_circuits_to_compile(slice_circuits_list,
                                    sampling_rate=sampling_rate)
def _tests():
    """Run tests on the module.
    """
    coupling_list = get_nearest_neighbor_coupling_list(2, 2)
    theta = [np.random.random() for _ in range(8)]
    circuit = optimize_circuit(get_uccsd_circuit('LiH', theta), coupling_list)
    slices = get_uccsd_slices(circuit, granularity=2)
    grouped_slices = get_uccsd_slices(circuit, granularity=2,
                                      dependence_grouping=True)
    angle_count = 0
    for uccsdslice in grouped_slices:
        print(uccsdslice.angles)
        print(uccsdslice.circuit)
        for angle in uccsdslice.angles:
            assert angle == slices[angle_count].angles[0]
            angle_count += 1

    print("grouped_slices_count: {}".format(len(grouped_slices)))
    assert angle_count == 40
Exemple #4
0
QUBIT6_SCL = get_full_states_concerned_list(6, NUM_STATES)
QUBIT6_MPA = get_maxA(6, NUM_STATES, QUBIT6_CQP)
GRAPE_QUBIT6_CONFIG = {
    "H0": QUBIT6_H0,
    "Hops": QUBIT6_HOPS,
    "Hnames": QUBIT6_HNAMES,
    "states_concerned_list": QUBIT6_SCL,
    "reg_coeffs": REG_COEFFS,
    "maxA": QUBIT6_MPA,
}

### UCCSD MOLECULE CONSTANTS ###

# H2
UCCSD_H2_THETA = [5.239368082827368, 1.5290813407594008, 4.701843728963671]
UCCSD_H2_FULL_CIRCUIT = optimize_circuit(
    get_uccsd_circuit("H2", UCCSD_H2_THETA), QUBIT2_CQP)
UCCSD_H2_SLICES = get_uccsd_slices(
    UCCSD_H2_FULL_CIRCUIT,
    granularity=SLICE_GRANULARITY,
    dependence_grouping=SLICE_DEPENDENCE_GROUPING)

# LiH
UCCSD_LIH_THETA = [
    0.86203, 3.8037, 3.3223, 1.766, 1.0846, 1.4558, 1.0592, 0.091974
]
UCCSD_LIH_FULL_CIRCUIT = optimize_circuit(
    get_uccsd_circuit("LiH", UCCSD_LIH_THETA), QUBIT4_CQP)
UCCSD_LIH_SLICES = get_uccsd_slices(
    UCCSD_LIH_FULL_CIRCUIT,
    granularity=SLICE_GRANULARITY,
    dependence_grouping=SLICE_DEPENDENCE_GROUPING)
Exemple #5
0
# Define convergence parameters and penalties.
convergence = {'rate': 2e-2, 'conv_target': 1e-3,
               'max_iterations': 1e3, 'learning_rate_decay': 1e3}
reg_coeffs = {}
use_gpu = False
sparse_H = False
show_plots = False
method = 'ADAM'
# Steps per nanosecond and nanoseconds per step
spn = 20.0
nps = 1 / spn

# Get slices to perform qoc on. The initial angle of each RZ
# gate does not matter.
theta = UCCSD_LIH_THETA
circuit = optimize_circuit(get_uccsd_circuit('LiH', theta),
                           connected_qubit_pairs)
uccsd_slices = get_uccsd_slices(circuit, granularity=SLICE_GRANULARITY,
                                dependence_grouping=True)

# https://ark.intel.com/products/91754/Intel-Xeon-Processor-E5-2680-v4-35M-Cache-2-40-GHz-
BROADWELL_CORE_COUNT = 14


### MAIN ###

def main():
    # Handle CLI.
    parser = argparse.ArgumentParser()
    parser.add_argument("--angle-start", type=float, default=0.0, help="the "
                        "inclusive lower bound of angles to optimize the "
                        "slice for (units in degrees, behaves like np.arange)")
                                   CONNECTED_QUBIT_PAIRS)
STATES_CONCERNED_LIST = get_full_states_concerned_list(NUM_QUBITS, NUM_STATES)
MAX_AMPLITUDE = get_maxA(NUM_QUBITS, NUM_STATES, CONNECTED_QUBIT_PAIRS)
METHOD = 'ADAM'
MAX_GRAPE_ITERATIONS = 1e3
DECAY = 1e3
REG_COEFFS = {}
USE_GPU = False
SPARSE_H = False
SHOW_PLOTS = False
# Wave steps per nanosecond of pulse time.
SPN = 20

# Get slices and information.
SLICE_GRANULARITY = 2
UCCSD_LIH_FULL_CIRCUIT = optimize_circuit(
    get_uccsd_circuit('LiH', UCCSD_LIH_THETA), CONNECTED_QUBIT_PAIRS)
UCCSD_LIH_SLICES = get_uccsd_slices(UCCSD_LIH_FULL_CIRCUIT,
                                    granularity=SLICE_GRANULARITY,
                                    dependence_grouping=True)

# Hyperparmeter optimization constants and search space.
MAX_HPO_ITERATIONS = 50
LR_LB = 1e-5
LR_UB = 1
DECAY_LB = 1
DECAY_UB = 1e5

### OBJECTS ###


class ProcessState(object):