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)
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
# pulse steps per nanosecond SPN = 20. # nanoseconds per pulse step NPS = 1 / SPN ### GATE DATA ### # fqc/experiments/Gate_Times.ipynb GATE_TIMES = {'h': 1.4, 'cx': 3.8, 'rz': 0.4, 'rx': 2.5, 'x': 2.5, 'swap': 7.4} _RZ = GATE_TIMES['rz'] ### GRAPE CONSTANTS ### REG_COEFFS = {} QUBIT2_CQP = get_nearest_neighbor_coupling_list(1, 2, directed=False) QUBIT2_H0 = np.zeros((NUM_STATES**2, NUM_STATES**2)) QUBIT2_HOPS, QUBIT2_HNAMES = get_Hops_and_Hnames(2, NUM_STATES, QUBIT2_CQP) QUBIT2_SCL = get_full_states_concerned_list(2, NUM_STATES) QUBIT2_MPA = get_maxA(2, NUM_STATES, QUBIT2_CQP) GRAPE_QUBIT2_CONFIG = { "H0": QUBIT2_H0, "Hops": QUBIT2_HOPS, "Hnames": QUBIT2_HNAMES, "states_concerned_list": QUBIT2_SCL, "reg_coeffs": REG_COEFFS, "maxA": QUBIT2_MPA, } QUBIT4_CQP = get_nearest_neighbor_coupling_list(2, 2, directed=False) QUBIT4_H0 = np.zeros((NUM_STATES**4, NUM_STATES**4))
from quantum_optimal_control.helper_functions.grape_functions import transmon_gate from quantum_optimal_control.main_grape.grape import Grape from quantum_optimal_control.core import hamiltonian d = 2 # this is the number of energy levels to consider (i.e. d-level qudits) max_iterations = 6000 decay = max_iterations / 2 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):
### CONSTANTS ### DATA_PATH = "" ANGLES = [90, 180, 270] ANGLE_CONSTANT = 180 TIME_MULTIPLIERS = [0.25, 0.5, 0.75] TIME_MULTIPLIER_CONSTANT = 0.5 JOBS_PER_SLICE = 5 BROADWELL_CORE_COUNT = 14 # Grape constants. NUM_QUBITS = 4 NUM_STATES = 2 CONNECTED_QUBIT_PAIRS = get_nearest_neighbor_coupling_list(2, 2, directed=False) H0 = np.zeros((NUM_STATES**NUM_QUBITS, NUM_STATES**NUM_QUBITS)) Hops, Hnames = get_Hops_and_Hnames(NUM_QUBITS, NUM_STATES, 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