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)
Esempio n. 2
0
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
Esempio n. 3
0
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)
Esempio n. 4
0
convergence = {'rate':0.01, 'max_iterations': max_iterations,
                       'conv_target':1e-3, 'learning_rate_decay':decay, 'min_grad': 1e-12, 'update_step': 20}
reg_coeffs = {}



N = 4
connected_qubit_pairs = util.get_nearest_neighbor_coupling_list(2, 2, directed=False)
H0 = np.zeros((d ** N, d ** N))
Hops, Hnames = hamiltonian.get_Hops_and_Hnames(N, d, connected_qubit_pairs)
states_concerned_list = hamiltonian.get_full_states_concerned_list(N, d)
maxA = hamiltonian.get_maxA(N, d, connected_qubit_pairs)



circuit = uccsd.get_uccsd_circuit('LiH')


slices = uccsd.get_uccsd_slices(circuit, granularity=1)
slices = [slice for slice in slices if not slice.parameterized]


def binary_search_for_shortest_pulse_time(min_time, max_time, tolerance=1):
    """Search between [min_time, max_time] up to 1ns tolerance. Assumes 20 steps per ns."""
    min_steps, max_steps = min_time * 20, max_time * 20
    while min_steps + 20 * tolerance < max_steps:  # just estimate to +- 1ns
        mid_steps = int((min_steps + max_steps) / 2)
        total_time = mid_steps / 20.0
        print('\n\ntrying total_time: %s for unitary of size %s' % (str(total_time), str(U.shape)))
        SS = Grape(H0, Hops, Hnames, U, total_time, mid_steps, states_concerned_list, convergence,
                         reg_coeffs=reg_coeffs,
Esempio n. 5
0
                   use_gpu=False,
                   sparse_H=False,
                   method='Adam',
                   maxA=maxA,
                   show_plots=False,
                   file_name=file_name,
                   data_path=data_path)
        if SS.l < SS.conv.conv_target:  # if converged, search lower half
            max_steps = mid_steps
        else:
            min_steps = mid_steps

    return mid_steps / 20


nah_circuit = uccsd.get_uccsd_circuit('NaH')
nah_circuit = util.circuitutil.optimize_circuit(nah_circuit)
coupling_list = util.circuitutil.get_nearest_neighbor_coupling_list(2, 4)
nah_circuit = util.circuitutil.optimize_circuit(nah_circuit, coupling_list)

from qiskit import QuantumCircuit, QuantumRegister
from copy import deepcopy


def indices(gate):
    return [qarg[1] for qarg in gate.qargs]


def gate_block_index(gate, blocking):
    if len(indices(gate)) == 1:
        return [indices(gate)[0] in grouping
Esempio n. 6
0
        total_time = mid_steps / 20.0
        print('\n\ntrying total_time: %s for unitary of size %s' % (str(total_time), str(U.shape)))
        SS = Grape(H0, Hops, Hnames, U, total_time, mid_steps, states_concerned_list, convergence,
                         reg_coeffs=reg_coeffs,
                         use_gpu=False, sparse_H=False, method='Adam', maxA=maxA,
                         show_plots=False, file_name=file_name, data_path=data_path)
        if SS.l < SS.conv.conv_target:  # if converged, search lower half
            max_steps = mid_steps
        else:
            min_steps = mid_steps

    return mid_steps / 20



beh2_circuit = uccsd.get_uccsd_circuit('BeH2')
beh2_circuit = util.circuitutil.optimize_circuit(beh2_circuit)
coupling_list = util.circuitutil.get_nearest_neighbor_coupling_list(2, 4)
beh2_circuit = util.circuitutil.optimize_circuit(beh2_circuit, coupling_list)


from qiskit import QuantumCircuit, QuantumRegister
from copy import deepcopy


def indices(gate):
    return [qarg[1] for qarg in gate.qargs]


def gate_block_index(gate, blocking):
    if len(indices(gate)) == 1:
Esempio n. 7
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 "
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):