当前位置: 首页>>代码示例>>Python>>正文


Python Simulation.save方法代码示例

本文整理汇总了Python中simulation.Simulation.save方法的典型用法代码示例。如果您正苦于以下问题:Python Simulation.save方法的具体用法?Python Simulation.save怎么用?Python Simulation.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在simulation.Simulation的用法示例。


在下文中一共展示了Simulation.save方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: square_toric_code_sim

# 需要导入模块: from simulation import Simulation [as 别名]
# 或者: from simulation.Simulation import save [as 别名]
def square_toric_code_sim(size, error_rate, n_trials, filename):
    """
    This function is square in more than one sense; it does everything
    the most vanilla way possible, and it uses a square grid to define 
    the torus. You put in an integer size, an error rate and a number
    of trials to execute, and it produces a pickled dict containing 
    the input to a simulation object in a file.
    """
    
    sim_lattice = SquareLattice((size,size))
    sim_dual_lattice = SquareLattice((size,size), is_dual=True)
    sim_model = depolarizing_model(error_rate)
    sim_code = toric_code(sim_lattice, sim_dual_lattice)
    sim_decoder = mwpm_decoder(sim_lattice, sim_dual_lattice)
    sim_log_ops = toric_log_ops((size,size))

    sim_keys = ['lattice', 'dual_lattice', 'error_model', 'code', 
                            'decoder', 'logical_operators', 'n_trials']

    sim_values = [sim_lattice, sim_dual_lattice, sim_model, sim_code, 
                                sim_decoder, sim_log_ops, n_trials]
    
    sim_dict = dict(zip(sim_keys, sim_values))

    sim = Simulation(**sim_dict)
    sim.run()
    sim.save(filename + '.sim')
开发者ID:silky,项目名称:py-qcode,代码行数:29,代码来源:utils.py

示例2: sim_from_file

# 需要导入模块: from simulation import Simulation [as 别名]
# 或者: from simulation.Simulation import save [as 别名]
def sim_from_file(filename):
    """
    The purpose of this function is to:

    + open a file containing a pickled dictionary of input values to a simulation,

    + initialize the objects which the corresponding `py_qcode.Simulation` takes as input,
    
    + run the simulation, and 

    + save the results to a file of the same name as the input, with a different extension.  
    """
    #Obsolete, scavenging code for pickle-independent implementation
    #(you can't pickle functions).
    with open(filename,'r') as phil:
        sim_dict = pkl.load(phil)
    sim = Simulation(**sim_dict)
    sim.run()

    split_name = filename.split('.')
    try:
        file_prefix, file_ext = split_name
    except ValueError:
        raise ValueError('Filenames are assumed to be of the form'+\
        ' "prefix.ext".')

    output_name = '.'.join([file_prefix, 'out'])

    sim.save(output_name)
开发者ID:silky,项目名称:py-qcode,代码行数:31,代码来源:utils.py

示例3: squoct_sim

# 需要导入模块: from simulation import Simulation [as 别名]
# 或者: from simulation.Simulation import save [as 别名]
def squoct_sim(size, error_rate, n_trials, filename):
    """
    Copypasta from above, maybe I'll un-pasta this later. 
    """
    
    sim_lattice = SquareOctagonLattice((size,size))
    sim_dual_lattice = SquareOctagonLattice((size,size), is_dual=True)
    sim_model = depolarizing_model(error_rate)
    sim_code = square_octagon_code(sim_lattice, sim_dual_lattice)
    sim_decoder = mwpm_decoder(sim_lattice, sim_dual_lattice)
    sim_log_ops = squoct_log_ops(sim_lattice.size)

    sim_keys = ['lattice', 'dual_lattice', 'error_model', 'code', 
                            'decoder', 'logical_operators', 'n_trials']

    sim_values = [sim_lattice, sim_dual_lattice, sim_model, sim_code, 
                                sim_decoder, sim_log_ops, n_trials]
    
    sim_dict = dict(zip(sim_keys, sim_values))

    sim = Simulation(**sim_dict)
    sim.run()
    sim.save(filename + '.sim')
开发者ID:silky,项目名称:py-qcode,代码行数:25,代码来源:utils.py

示例4: run_simu

# 需要导入模块: from simulation import Simulation [as 别名]
# 或者: from simulation.Simulation import save [as 别名]
def run_simu(params):
    simu = Simulation(params, max_time=max_time)
    simu.run()
    simu.save()
    return simu
开发者ID:pwais,项目名称:bandit_policy_simulator,代码行数:7,代码来源:run_experiments.py


注:本文中的simulation.Simulation.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。