def _get_circuits_to_compile(slice_circuits_list):
    circuits_to_compile = []
    for slice_circuits, blocking in slice_circuits_list:
        for slice_circuit, block, connected_qubit_pairs in zip(
                slice_circuits, blocking.blocks,
                blocking.connected_qubit_pairs_list):
            for index in block:
                assert len(slice_circuit.qregs) == 1
                slice_circuit.iden(slice_circuit.qregs[0][index])
            slice_circuit = squash_circuit(slice_circuit)

            for subslice in get_uccsd_slices(slice_circuit,
                                             granularity=2,
                                             dependence_grouping=True):
                circuits_to_compile.append(
                    (subslice.circuit, connected_qubit_pairs))
    return circuits_to_compile
Exemplo n.º 2
0
    "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)

# BeH2
UCCSD_BEH2_THETA = [
Exemplo n.º 3
0


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,
                         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
Exemplo n.º 4
0
for slice_circuit, block, connected_qubit_pairs in zip(
        slice_circuits, blocking.blocks, blocking.connected_qubit_pairs_list):
    for index in block:
        assert len(slice_circuit.qregs) == 1
        slice_circuit.iden(slice_circuit.qregs[0][index])

    slice_circuit = util.squash_circuit(slice_circuit)
    N = slice_circuit.width()
    H0 = hamiltonian.get_H0(N, d)
    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)
    max_time = (3 * N) * 5.0 * graph_p

    time = 0.0
    for subslice in uccsd.get_uccsd_slices(slice_circuit, granularity=1):
        if subslice.parameterized:
            time += util.circuitutil.get_max_pulse_time(subslice.circuit)
        else:
            U = util.get_unitary(subslice.circuit)
            time += binary_search_for_shortest_pulse_time(0.0,
                                                          max_time,
                                                          tolerance=0.3)

    times.append(time)

print('\n\n\n')
print(times)
print('TIME FOR SLICE IS:')
print(max(times))
Exemplo n.º 5
0
times = []
for slice_circuit, block, connected_qubit_pairs in zip(
        slice_circuits, blocking.blocks, blocking.connected_qubit_pairs_list):
    for index in block:
        assert len(slice_circuit.qregs) == 1
        slice_circuit.iden(slice_circuit.qregs[0][index])

    slice_circuit = util.squash_circuit(slice_circuit)
    N = slice_circuit.width()
    H0 = hamiltonian.get_H0(N, d)
    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)
    max_time = (2**N) * 5.0

    time = 0.0
    for subslice in uccsd.get_uccsd_slices(slice_circuit,
                                           granularity=2,
                                           dependence_grouping=True):
        U = util.get_unitary(subslice.circuit)
        time += binary_search_for_shortest_pulse_time(0.0,
                                                      max_time,
                                                      tolerance=0.3)

    times.append(time)

print('\n\n\n')
print(times)
print('TIME FOR SLICE IS:')
print(max(times))
Exemplo n.º 6
0
               '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)")
    parser.add_argument("--angle-stop", type=float, default=1.0, help="the "
                        "exclusive upper bound of angles to optimize the "
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):
    """A class to track the state of an optimization loop.
    Fields:
Exemplo n.º 8
0
}
reg_coeffs = {}

N = 4
connected_qubit_pairs = util.get_nearest_neighbor_coupling_list(2,
                                                                2,
                                                                directed=False)
H0 = hamiltonian.get_H0(N, d)
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=2,
                                dependence_grouping=True)


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,