Exemplo n.º 1
0
    def compute_optimal_kenn(self):
        f = basics.Basics(layers=1, resolution=self.resolution, amplitude=self.amplitude, bound_displacements=self.bound_displacements, efficiency=self.efficiency, pflip=self.pflip)
        f.define_actions()
        self.optimal_kenn_resolution= 1-np.min(f.err_kennedy(f.actions))
        np.save("bounds_optimals_and_limits/1layers_probs_resolution0.1/" + str(self.amplitude),self.optimal_kenn_resolution)

        del f
        return
Exemplo n.º 2
0
 def compute_optimal_2l(self):
     f = basics.Basics(layers=2, resolution=self.resolution, amplitude=self.amplitude, bound_displacements=self.bound_displacements, efficiency=self.efficiency, pflip=self.pflip)
     f.define_actions()
     probs=[]
     for b1 in f.actions:
         for b20 in f.actions:
             for b21 in f.actions:
                 probs.append(f.probability_error([b1,b20,b21]))
     del f
     self.optimal_2l_resolution = 1-np.min(probs)
     del probs
     np.save("bounds_optimals_and_limits/2layers_probs_resolution0.1/" + str(self.amplitude),self.optimal_2l_resolution)
     return
Exemplo n.º 3
0
import numpy as np
import pandas as pd

bets = pd.read_csv("solobetas.csv")
bets = bets.to_numpy()

betsatts = pd.read_csv("betas_atts.csv")
betsatts = betsatts.to_numpy()

print(np.where(bets[:,1] - bets[:,2] == np.max(bets[:,1] - bets[:,2]) ))
print(np.where(bets[:,1] - bets[:,2] == np.max(bets[:,1] - bets[:,2]) ))
print(np.where(bets[:,1] - bets[:,2] == np.max(bets[:,1] - bets[:,2]) ))
print(np.where(bets[:,1] - bets[:,2] == np.max(bets[:,1] - bets[:,2]) ))

import basics
b = basics.Basics(layers=1)
Exemplo n.º 4
0
import random
import asyncio
import basics

from discord.ext import commands

bot = commands.Bot(command_prefix=config.command_prefix)
bot.remove_command("help") # Heck the normal help command

async def status():
    await bot.wait_until_ready()
    while True:
        await bot.change_presence(activity=discord.Activity(name=f"{random.choice(config.status_q)} | {config.command_prefix}help", type=2), status=discord.Status.dnd)
        await asyncio.sleep(1800)

@bot.event
async def on_command_error(ctx, error):
    print(f"Error: \"{str(error)}\" when someone typed \"{ctx.message.content}\"")

@bot.event
async def on_ready():
    members = 0
    
    for guild in bot.guilds:
        members += guild.member_count
        
    print(f"Started {bot.user.name} on {len(bot.guilds)} servers with {members} members!")

bot.loop.create_task(status())
bot.add_cog(basics.Basics(bot))
bot.run(config.token)
Exemplo n.º 5
0
    def __init__(self,  amplitude=.4, layers=2, resolution=0.1, number_phases=2, bound_displacements=1, guessing_rule="None", searching_method="ucb", ep=0.01, ucb_method="ucb1", states_wasted=10**4, soft_ts=1, soft_ts_guess=1, std_energy=0, ep_method ="exp-decay", strawberry_fields="OFF",efficiency=1,method_guess="undefined", min_ep = 0.01, time_tau=1000, efficient_time=True, pflip = 0, algorithm="standard", strange_factor_ucbeff=1, prob_eff=0.01, save_tables="Completely-False", ts_method= "std"):

        self.info = " amplitude:" + str(amplitude) + "\nlayers: "+str(layers) + "\n number_phases: " + str(number_phases) + "\n search_method: " +str(searching_method)+ "\n resolution: " +str( resolution) + "\n bound_displacements: "+str(bound_displacements) + "\n guessing_rule: " +str( guessing_rule) + "\n method_guess : "+str(method_guess) + "dark counts rate (efficiency): " + str(efficiency) + "\n Phase flip probability: "+ str(pflip) + " \n ************  \n ************ \n " +  "epsilon: "+str(ep) + "\n epsilon_greedy method: "+ str( ep_method) +  "\n min_ep : "+str(min_ep) + "\n time_tau (exp decay ep-greedy): "+str(time_tau) + "\n \n  **** UCB DETAILS *** \n \n " + " ucb_method: " + str(ucb_method) + "**** thomspon sampling details: " + "\n soft_ts: " + str(soft_ts) + "\n \n **** TS DETAILS \n ts_method (if update towards q instead of reward): " + str(ts_method) + "\nsoft_ts: "+str(soft_ts)

        if algorithm == "UCB-eff":
            self.info = "\n \n ********** \n \n ###### ALGORITHM OF IS Q-LEARNING PROVABLY EFFICIENT:" + "c : " + str(strange_factor_ucbeff) + "\n prob_eff: (with 1-p the regret is at most O(\sqrt{T})): " +str(prob_eff)


        self.amplitude = amplitude
        self.layers = layers
        self.resolution = resolution
        self.number_phases=number_phases
        self.bound_displacements = bound_displacements
        self.states_wasted=states_wasted

        self.searching_method = searching_method
        self.guessing_rule = guessing_rule
        self.efficiency = efficiency
        self.pflip = pflip
        self.efficient_time = efficient_time

        self.ep = ep
        self.min_ep = min_ep
        self.time_tau = time_tau

        self.bobs = {}
        self.ep_method = ep_method
        self.ucb_method = ucb_method
        self.method_guess=method_guess

        self.soft_ts = soft_ts
        self.ts_method = ts_method

        self.std_energy = std_energy

        self.strawberry_fields = strawberry_fields

        bb = basics.Basics(amplitude=self.amplitude, layers=1,bound_displacements=self.bound_displacements, resolution=self.resolution)
        self.homodyne_limit = bb.homodyne()
        del bb

        self.opt_kenn = np.genfromtxt("bounds_optimals_and_limits/kennedy_probs/"+str(np.round(self.amplitude,2))+".csv", delimiter=",")
        self.opt_2l = np.genfromtxt("bounds_optimals_and_limits/2layers_probs/"+str(np.round(self.amplitude,2))+".csv", delimiter=",")
        # self.opt_kenn_resolution = self.compute_optimal_kenn()
        self.optimal_value = 0
        # if (self.layers == 1)&(self.resolution==0.1)&(self.bound_displacements==1)&(np.round(self.amplitude,2)==self.amplitude):
        #     self.optimal_value = np.load("bounds_optimals_and_limits/1layers_probs_resolution0.1/"+str(np.round(self.amplitude,2))+".npy")
        #     self.cte_LR = 1505.5002588209475
        if self.layers == 2:
            self.opt_2l_resolution01 = np.load("bounds_optimals_and_limits/2layers_probs_resolution0.1/"+str(np.round(self.amplitude,2))+".npy")
            self.optimal_value = self.opt_2l_resolution01
            self.cte_LR = 1505.5002588209475 #(the one for bandits...)

        elif self.layers==1:
            #for the bandit scenarii...
            b = basics.Basics(amplitude=self.amplitude, layers=1,bound_displacements=self.bound_displacements, resolution=self.resolution)
            b.define_actions()
            dol_prob= [b.err_dolinar(disp) for disp in b.actions]
            self.optimal_value =max(dol_prob)

            reg_coeff=0
            for p in dol_prob:
                if p!=self.optimal_value:
                    reg_coeff += (self.optimal_value -p)/Kull(p,self.optimal_value)

            self.cte_LR = reg_coeff
        else:
            self.optimal_value = "Compute it with DP!"
        self.algorithm = algorithm
        self.strange_factor_ucbeff = strange_factor_ucbeff
        self.prob_eff = prob_eff

        self.times_bkp_tables = []
        for k in range(1,int(np.log10(self.states_wasted))): #the +1 is just in case...
            self.times_bkp_tables = np.append(self.times_bkp_tables, np.arange(10**k, 10**(k+1), 10**k))

        if self.efficient_time == True:
            self.times_saved = self.times_bkp_tables
        else:
            self.times_saved = np.arange(1,self.states_wasted+1)
        self.save_tables = save_tables