# logFormatter = logging.Formatter("%(asctime)s [%(threadName)-12.12s]"
#                                  "[%(levelname)-5.5s]  %(message)s")
# rootLogger = logging.getLogger()
# rootLogger.setLevel(logging.DEBUG)
# # consoleHandler = logging.StreamHandler()
# # consoleHandler.setFormatter(logFormatter)
# # rootLogger.addHandler(consoleHandler)
# fileHandler = logging.FileHandler(output_file_name[:-4] + '.log')
# fileHandler.setFormatter(logFormatter)
# fileHandler.setLevel(logging.DEBUG)
# rootLogger.addHandler(fileHandler)

logging.info('Output file name will be "{}"'.format(output_file_name))

# ------ start optimization
results = optimization.find_best_protocol(
    problem_specification=dict(model=model,
                               model_parameters=model_parameters,
                               task='critical point'),
    optimization_specs=dict(
        protocol=protocol,
        protocol_options=dict(num_frequencies=num_frequencies),
        optimization_method=optimization_method,
        initial_parameters=initial_parameters,
        parameters_constraints=parameters_constraints,
        optimization_options=dict(xatol=1e-16, fatol=1e-16, disp=True)),
    other_options=dict(scan_times=np.linspace(2, 3.2, 500)))

# ------ save results to file
results.to_csv(output_file_name)
Esempio n. 2
0
import numpy as np
import pandas as pd
import logging
if '../../' not in sys.path:
    sys.path.append('../../')
import src.optimization as optimization
import src.protocol_ansatz as protocol_ansatz
from src.utils import autonumber_filename, basic_logger_configuration

output_file_name = os.path.basename(__file__)[7:-3] + '.csv'
output_file_name = autonumber_filename(output_file_name)
basic_logger_configuration(filename=output_file_name[:-3] + 'log')
logging.info('Output file name will be "{}"'.format(output_file_name))

# ------ start optimization
results = optimization.find_best_protocol(
    problem_specification=dict(model='rabi',
                               model_parameters=dict(N=100,
                                                     Omega=100,
                                                     omega_0=1.),
                               task=dict(initial_intensity=0,
                                         final_intensity=10)),
    optimization_specs=dict(protocol='crab',
                            protocol_options=dict(num_frequencies=8),
                            optimization_method='Nelder-Mead',
                            parameters_constraints=[-20, 20]),
    other_options=dict(scan_times=np.linspace(4, 20, 400)))

# ------ save results to file
results.to_csv(output_file_name)
Esempio n. 3
0
# rootLogger.addHandler(consoleHandler)
fileHandler = logging.FileHandler(output_file_name[:-4] + '.log')
fileHandler.setFormatter(logFormatter)
fileHandler.setLevel(logging.DEBUG)
rootLogger.addHandler(fileHandler)


logging.info('Output file name will be "{}"'.format(output_file_name))

# ------ start optimization
results = optimization.find_best_protocol(
    problem_specification=dict(
        model=model,
        model_parameters=model_parameters,
        task='critical point state generation'
    ),
    optimization_specs=dict(
        protocol=protocol,
        optimization_method=optimization_method,
        initial_parameters=initial_parameters,
        parameters_constraints=parameters_constraints
    ),
    other_options=dict(
        scan_times=np.linspace(0.1, 2, 100)
    )
)

# ------ save results to file
results.to_csv(output_file_name)

import pandas as pd
import logging
if '../../' not in sys.path:
    sys.path.append('../../')
import src.optimization as optimization
import src.protocol_ansatz as protocol_ansatz
from src.utils import autonumber_filename, basic_logger_configuration

output_file_name = os.path.basename(__file__)[7:-3] + '.csv'
output_file_name = autonumber_filename(output_file_name)
basic_logger_configuration(filename=output_file_name[:-3] + 'log')
logging.info('Output file name will be "{}"'.format(output_file_name))

# ------ start optimization
num_frequencies = 8
results = optimization.find_best_protocol(
    problem_specification=dict(model='lz',
                               model_parameters=dict(omega_0=1),
                               task=dict(initial_intensity=-5,
                                         final_intensity=5)),
    optimization_specs=dict(
        protocol='crab',
        protocol_options=dict(num_frequencies=num_frequencies),
        optimization_method='Nelder-Mead',
        parameters_constraints=[-10, 10],
        initial_parameters=[[-1, 1]] * (2 * num_frequencies)),
    other_options=dict(scan_times=np.linspace(0.01, 10, 400)))

# ------ save results to file
results.to_csv(output_file_name)
Esempio n. 5
0
# ------ start optimization
num_frequencies = 8
protocol = protocol_ansatz.CRABProtocolAnsatz(num_frequencies=num_frequencies)
protocol.generate_rnd_frequencies_each_tf = False
for idx in range(num_frequencies):
    protocol.hyperpars['nuk' + str(idx + 1)] = 0
protocol.fill_hyperpar_value(y0=-5, y1=5)

results = optimization.find_best_protocol(
    problem_specification=dict(
        model='lz',
        model_parameters=dict(omega_0=1),
        task=dict(initial_intensity=-5, final_intensity=5)
    ),
    optimization_specs=dict(
        protocol=protocol,
        protocol_options=dict(num_frequencies=num_frequencies),
        optimization_method='Nelder-Mead',
        parameters_constraints=[-10, 10],
        initial_parameters=[0] * (2 * num_frequencies),
        optimization_options=dict(maxiter=1e5, maxfev=1e5,
                                  xatol=1e-8, fatol=1e-8, adaptive=True)
    ),
    other_options=dict(
        scan_times=np.linspace(1, 2, 30)
    )
)

# ------ save results to file
results.to_csv(output_file_name)
Esempio n. 6
0
rootLogger.setLevel(logging.DEBUG)
fileHandler = logging.FileHandler(output_file_name[:-4] + '.log')
fileHandler.setFormatter(logFormatter)
fileHandler.setLevel(logging.DEBUG)
rootLogger.addHandler(fileHandler)


logging.info('Output file name will be "{}"'.format(output_file_name))

# ------ start optimization
results = optimization.find_best_protocol(
    problem_specification=dict(
        model=model,
        model_parameters=model_parameters,
        task=task
    ),
    optimization_specs=dict(
        protocol=protocol,
        optimization_method=optimization_method,
        parameters_constraints=parameters_constraints,
        initial_parameters=initial_parameters
    ),
    other_options=dict(
        scan_times=np.linspace(time_initial, time_final, time_subintervals)
    )
)

# ------ save results to file
results.to_csv(output_file_name)

Esempio n. 7
0
import logging
if '../../' not in sys.path:
    sys.path.append('../../')
import src.optimization as optimization
import src.protocol_ansatz as protocol_ansatz
from src.utils import autonumber_filename, basic_logger_configuration

output_file_name = os.path.basename(__file__)[7:-3] + '.csv'
output_file_name = autonumber_filename(output_file_name)
basic_logger_configuration(filename=output_file_name[:-3] + 'log')
logging.info('Output file name will be "{}"'.format(output_file_name))

third_time = lambda t: t / 3.
twothirds_time = lambda t: 2 * t / 3.
initial_parameters = [[-1, 1]] * 3 + [third_time, twothirds_time]
# ------ start optimization
results = optimization.find_best_protocol(
    problem_specification=dict(model='lmg',
                               model_parameters=dict(num_spins=50),
                               task=dict(initial_intensity=0,
                                         final_intensity=2)),
    optimization_specs=dict(
        protocol=protocol_ansatz.TripleBangProtocolAnsatz(),
        optimization_method='Nelder-Mead',
        parameters_constraints=[-10, 10],
        initial_parameters=initial_parameters),
    other_options=dict(scan_times=np.linspace(10, 20, 400)))

# ------ save results to file
results.to_csv(output_file_name)
    sys.path.append('../../')
import src.optimization as optimization
import src.protocol_ansatz as protocol_ansatz
from src.utils import autonumber_filename, basic_logger_configuration

output_file_name = os.path.basename(__file__)[7:-3] + '.csv'
output_file_name = autonumber_filename(output_file_name)
basic_logger_configuration(filename=output_file_name[:-3] + 'log')
logging.info('Output file name will be "{}"'.format(output_file_name))

third_time = lambda t: t / 3.
twothirds_time = lambda t: 2 * t / 3.
initial_parameters = [[-1, 1]] * 3 + [third_time, twothirds_time]
# ------ start optimization
results = optimization.find_best_protocol(
    problem_specification=dict(model='rabi',
                               model_parameters=dict(N=100,
                                                     Omega=100,
                                                     omega_0=1.),
                               task=dict(initial_intensity=0,
                                         final_intensity=10)),
    optimization_specs=dict(
        protocol=protocol_ansatz.TripleBangProtocolAnsatz(),
        optimization_method='powell',
        parameters_constraints=[-20, 20],
        initial_parameters=initial_parameters),
    other_options=dict(scan_times=np.linspace(4, 20, 400)))

# ------ save results to file
results.to_csv(output_file_name)
Esempio n. 9
0
import os
import sys
import numpy as np
import pandas as pd
import logging
if '../../' not in sys.path:
    sys.path.append('../../')
import src.optimization as optimization
import src.protocol_ansatz as protocol_ansatz
from src.utils import autonumber_filename, basic_logger_configuration

output_file_name = os.path.basename(__file__)[7:-3] + '.csv'
output_file_name = autonumber_filename(output_file_name)
basic_logger_configuration(filename=output_file_name[:-3] + 'log')
logging.info('Output file name will be "{}"'.format(output_file_name))

# ------ start optimization
results = optimization.find_best_protocol(
    problem_specification=dict(model='lmg',
                               model_parameters=dict(num_spins=50),
                               task=dict(initial_intensity=0,
                                         final_intensity=2)),
    optimization_specs=dict(protocol='crab',
                            protocol_options=dict(num_frequencies=8),
                            optimization_method='Nelder-Mead',
                            parameters_constraints=[-10, 10]),
    other_options=dict(scan_times=np.linspace(10, 20, 400)))

# ------ save results to file
results.to_csv(output_file_name)
Esempio n. 10
0
# consoleHandler = logging.StreamHandler()
# consoleHandler.setFormatter(logFormatter)
# rootLogger.addHandler(consoleHandler)
fileHandler = logging.FileHandler(output_file_name[:-4] + '.log')
fileHandler.setFormatter(logFormatter)
fileHandler.setLevel(logging.DEBUG)
rootLogger.addHandler(fileHandler)


logging.info('Output file name will be "{}"'.format(output_file_name))

# ------ start optimization
results = optimization.find_best_protocol(
    problem_specification=dict(
        model=model,
        model_parameters=model_parameters,
        task='critical point state generation'
    ),
    optimization_specs=dict(
        protocol=protocol, protocol_options=dict(num_frequencies=2),
        optimization_method=optimization_method
    ),
    other_options=dict(
        scan_times=np.linspace(0.1, 4, 100)
    )
)

# ------ save results to file
results.to_csv(output_file_name)

Esempio n. 11
0
# consoleHandler.setFormatter(logFormatter)
# rootLogger.addHandler(consoleHandler)
fileHandler = logging.FileHandler(output_file_name[:-4] + '.log')
fileHandler.setFormatter(logFormatter)
fileHandler.setLevel(logging.DEBUG)
rootLogger.addHandler(fileHandler)


logging.info('Output file name will be "{}"'.format(output_file_name))

# ------ start optimization
results = optimization.find_best_protocol(
    problem_specification=dict(
        model=model,
        model_parameters=model_parameters,
        task=task
    ),
    optimization_specs=dict(
        protocol=protocol,
        optimization_method=optimization_method,
        parameters_constraints=parameters_constraints
    ),
    other_options=dict(
        scan_times=np.linspace(0.1, 4, 200)
    )
)

# ------ save results to file
results.to_csv(output_file_name)

rootLogger.setLevel(logging.DEBUG)
# consoleHandler = logging.StreamHandler()
# consoleHandler.setFormatter(logFormatter)
# rootLogger.addHandler(consoleHandler)
fileHandler = logging.FileHandler(output_file_name[:-4] + '.log')
fileHandler.setFormatter(logFormatter)
fileHandler.setLevel(logging.DEBUG)
rootLogger.addHandler(fileHandler)

logging.info('Output file name will be "{}"'.format(output_file_name))

# ------ start optimization
num_spins_list = np.arange(50, 210, 10)  # [50, 60, ..., 140, 150]
tf_results = np.zeros(shape=(len(num_spins_list),
                             2))  # will contain (num_spin, tf)
for idx, num_spins in enumerate(num_spins_list):
    logging.info('Starting optimization with {} spins'.format(num_spins))
    results = optimization.find_best_protocol(
        problem_specification=dict(model=model,
                                   model_parameters=dict(num_spins=num_spins),
                                   task='critical point state generation'),
        optimization_specs=dict(protocol=protocol,
                                optimization_method=optimization_method),
        other_options=dict(scan_times=np.arange(1, 2, 0.01),
                           stopping_condition=0.99))
    tf_results[idx] = [num_spins, results.iloc[-1]['tf']]

tf_results = pd.DataFrame(tf_results, columns=['num_spins', 'tf'])
# ------ save results to file
tf_results.to_csv(output_file_name)
Esempio n. 13
0
import os
import sys
import numpy as np
import pandas as pd
import logging
if '../../' not in sys.path:
    sys.path.append('../../')
import src.optimization as optimization
import src.protocol_ansatz as protocol_ansatz
from src.utils import autonumber_filename, basic_logger_configuration

output_file_name = os.path.basename(__file__)[7:-3] + '.csv'
output_file_name = autonumber_filename(output_file_name)
basic_logger_configuration(filename=output_file_name[:-3] + 'log')
logging.info('Output file name will be "{}"'.format(output_file_name))

# ------ start optimization
results = optimization.find_best_protocol(
    problem_specification=dict(model='lz',
                               model_parameters=dict(omega_0=1),
                               task=dict(initial_intensity=-5,
                                         final_intensity=5)),
    optimization_specs=dict(protocol='doublebang',
                            optimization_method='Powell',
                            parameters_constraints=[-30, 30],
                            initial_parameters=[[-2, 2], 'halftime', [-2, 2]]),
    other_options=dict(scan_times=np.linspace(0.01, 10, 400)))

# ------ save results to file
results.to_csv(output_file_name)
logFormatter = logging.Formatter("%(asctime)s [%(threadName)-12.12s]"
                                 "[%(levelname)-5.5s]  %(message)s")
rootLogger = logging.getLogger()
rootLogger.setLevel(logging.DEBUG)
# consoleHandler = logging.StreamHandler()
# consoleHandler.setFormatter(logFormatter)
# rootLogger.addHandler(consoleHandler)
fileHandler = logging.FileHandler(output_file_name[:-4] + '.log')
fileHandler.setFormatter(logFormatter)
fileHandler.setLevel(logging.DEBUG)
rootLogger.addHandler(fileHandler)

logging.info('Output file name will be "{}"'.format(output_file_name))

# ------ start optimization
results = optimization.find_best_protocol(
    problem_specification=dict(model=model,
                               model_parameters=model_parameters,
                               task='critical point'),
    optimization_specs=dict(protocol=protocol,
                            optimization_method=optimization_method,
                            initial_parameters=initial_parameters,
                            parameters_constraints=parameters_constraints,
                            optimization_options=dict(xtol=1e-16,
                                                      ftol=1e-16,
                                                      disp=False)),
    other_options=dict(scan_times=np.linspace(0.1, 20, 1000)))

# ------ save results to file
results.to_csv(output_file_name)
Esempio n. 15
0
import os
import sys
import numpy as np
import pandas as pd
import logging
if '../../' not in sys.path:
    sys.path.append('../../')
import src.optimization as optimization
import src.protocol_ansatz as protocol_ansatz
from src.utils import autonumber_filename, basic_logger_configuration

output_file_name = os.path.basename(__file__)[7:-3] + '.csv'
output_file_name = autonumber_filename(output_file_name)
basic_logger_configuration(filename=output_file_name[:-3] + 'log')
logging.info('Output file name will be "{}"'.format(output_file_name))

# ------ start optimization
results = optimization.find_best_protocol(
    problem_specification=dict(model='lmg',
                               model_parameters=dict(num_spins=20),
                               task=dict(initial_intensity=0,
                                         final_intensity=2)),
    optimization_specs=dict(protocol='doublebang',
                            optimization_method='Powell',
                            parameters_constraints=[-10, 10]),
    other_options=dict(scan_times=np.linspace(0.1, 20, 400)))

# ------ save results to file
results.to_csv(output_file_name)
rootLogger.addHandler(fileHandler)

logging.info('Output file name will be "{}"'.format(output_file_name))

# ------ start optimization
Omegas_list = np.arange(20, 210, 10)
tf_results = np.zeros(shape=(len(Omegas_list),
                             6))  # will contain (num_spin, tf)
for idx, Omega in enumerate(Omegas_list):
    logging.info('Starting optimization with {} spins'.format(Omega))
    results = optimization.find_best_protocol(
        problem_specification=dict(model=model,
                                   model_parameters=dict(N=Omega,
                                                         Omega=Omega,
                                                         omega_0=1.),
                                   task='critical point'),
        optimization_specs=dict(protocol=protocol,
                                optimization_method=optimization_method,
                                optimization_options=dict(xtol=1e-8,
                                                          ftol=1e-8,
                                                          disp=True)),
        other_options=dict(scan_times=np.arange(1, 3, 0.01),
                           stopping_condition=0.999))
    tf_results[idx][0] = Omega
    tf_results[idx][1:] = results.iloc[-1]

tf_results = pd.DataFrame(tf_results,
                          columns=['Omega', 'tf', 'fid', 'y0', 't1', 'y1'])
# ------ save results to file
tf_results.to_csv(output_file_name)