Best Python code snippet using slash
task_lmdata.py
Source:task_lmdata.py
1import numpy as np2import os3from tqdm import tqdm4from .loader import Korpora5from .utils import default_korpora_path6def create_lmdata(args):7 os.makedirs(os.path.abspath(args.output_dir), exist_ok=True)8 sampling_ratio = args.sampling_ratio9 if sampling_ratio is not None:10 sampling_ratio = float(sampling_ratio)11 if not (0 < sampling_ratio < 1):12 raise ValueError('`sampling_ratio` must be None or (0, 1) float')13 n_first_samples = args.n_first_samples14 np.random.seed(args.seed)15 selector = Selector(sampling_ratio, args.min_length, args.max_length)16 root_dir = args.root_dir17 if root_dir is None:18 root_dir = default_korpora_path19 force_download = args.force_download20 multilingual = args.multilingual21 corpus_names = check_corpus(root_dir, args.corpus)22 status = [['', name, ' - ', ''] for name in corpus_names]23 for i_corpus, name in enumerate(corpus_names):24 if not args.save_each and i_corpus > 0:25 mode = 'a'26 else:27 mode = 'w'28 filename = f'{name}.train' if args.save_each else 'all.train'29 lmdata_path = f'{args.output_dir}/{filename}'30 sent_iterator = tqdm(31 ITERATE_TEXTS[name](root_dir, force_download, multilingual),32 desc=f'Create train data from {name}'33 )34 print_status(status)35 n_sampled = 036 with open(lmdata_path, mode, encoding='utf-8') as f:37 for i_sent, sent in enumerate(sent_iterator):38 if not selector.use(sent):39 continue40 f.write(f'{sent}\n')41 n_sampled += 142 if (n_first_samples is not None) and (n_first_samples <= n_sampled):43 break44 status[i_corpus][0] = ' x '45 status[i_corpus][2] = n_sampled46 status[i_corpus][3] = filename47 print_status(status)48class Selector:49 def __init__(self, sampling_ratio, min_length, max_length):50 if isinstance(min_length, int) and min_length < 0:51 min_length = None52 if isinstance(max_length, int) and max_length < 0:53 max_length = None54 self.sampling_ratio = sampling_ratio55 self.min_length = min_length56 self.max_length = max_length57 def use(self, text):58 length = len(text)59 if (self.min_length is not None) and (length < self.min_length):60 return False61 if (self.max_length is not None) and (length > self.max_length):62 return False63 if self.sampling_ratio is None:64 return True65 return np.random.rand() < self.sampling_ratio66def check_corpus(root_dir, corpus_names):67 if (corpus_names == 'all') or (corpus_names[0] == 'all'):68 corpus_names = list(ITERATE_TEXTS)69 if isinstance(corpus_names, str):70 corpus_names = [corpus_names]71 available = []72 for name in corpus_names:73 if name not in ITERATE_TEXTS:74 print(f'Not provide {name} corpus. Check the `corpus` argument')75 continue76 if Korpora.exists(name, root_dir=root_dir):77 available.append(name)78 if not available:79 raise ValueError(80 'Not found any proper corpus name. Check the `corpus` argument')81 return available82def print_status(status):83 max_len = max(max(len(row[3]) for row in status), 9)84 form = '| {:4} | {:25} | {:10} | {} |'85 print('\n\n' + form.format('Done', 'Corpus name',86 'Num sents', 'File name' + ' ' * (max_len - 9)))87 print(form.format('-' * 4, '-' * 25, '-' * 10, '-' * max_len))88 for finish, name, num_sent, filename in status:89 if not filename:90 filename = ' ' * max_len91 else:92 filename += ' ' * (max_len - len(filename))93 print(form.format(finish, name, num_sent, filename))94def iterate_kcbert(root_dir, force_download, multilingual=False):95 Korpora.fetch('kcbert', root_dir, force_download)96 with open(f'{root_dir}/kcbert/20190101_20200611_v2.txt', encoding='utf-8') as f:97 for line in f:98 line = line.strip()99 if not line:100 continue101 yield line102def iterate_korean_chatbot_data(root_dir, force_download, multilingual=False):103 corpus = Korpora.load('korean_chatbot_data', root_dir, force_download)104 for sents in [corpus.train.texts, corpus.train.pairs]:105 for sent in sents:106 if not sent:107 continue108 yield sent109def iterate_korean_hate_speech(root_dir, force_download, multilingual=False):110 corpus = Korpora.load('korean_hate_speech', root_dir, force_download)111 for sents in [corpus.train.texts, corpus.dev.texts, corpus.unlabeled.texts]:112 for sent in sents:113 yield sent114def iterate_korean_parallel_koen_news(root_dir, force_download, multilingual):115 corpus = Korpora.load('korean_parallel_koen_news',116 root_dir, force_download)117 data = [corpus.train.texts, corpus.dev.texts, corpus.test.texts]118 if multilingual:119 data += [corpus.train.pairs, corpus.dev.pairs, corpus.test.pairs]120 for sents in data:121 for sent in sents:122 yield sent123def iterate_korean_petitions(root_dir, force_download, multilingual=False):124 corpus = Korpora.load('korean_petitions', root_dir, force_download)125 for example in corpus.train:126 yield example.title127 yield example.text128def iterate_kornli(root_dir, force_download, multilingual=False):129 corpus = Korpora.load('kornli', root_dir, force_download)130 for data in [corpus.multinli_train, corpus.snli_train, corpus.xnli_dev, corpus.xnli_test]:131 for sent in data.texts:132 yield sent133 for sent in data.pairs:134 yield sent135def iterate_korsts(root_dir, force_download, multilingual=False):136 corpus = Korpora.load('korsts', root_dir, force_download)137 for data in [corpus.train, corpus.dev, corpus.test]:138 for sent in data.texts:139 yield sent140 for sent in data.pairs:141 yield sent142def iterate_kowikitext(root_dir, force_download, multilingual=False):143 Korpora.fetch('kowikitext', root_dir, force_download)144 paths = [145 f'{root_dir}/kowikitext/kowikitext_20200920.train',146 f'{root_dir}/kowikitext/kowikitext_20200920.dev',147 f'{root_dir}/kowikitext/kowikitext_20200920.test'148 ]149 for path in paths:150 with open(path, encoding='utf-8') as f:151 for line in f:152 line = line.strip()153 if not line or (line[0] == '=' and line[-1] == '='):154 continue155 yield line156def iterate_namuwikitext(root_dir, force_download, multilingual=False):157 Korpora.fetch('namuwikitext', root_dir, force_download)158 paths = [159 f'{root_dir}/namuwikitext/namuwikitext_20200302.train',160 f'{root_dir}/namuwikitext/namuwikitext_20200302.dev',161 f'{root_dir}/namuwikitext/namuwikitext_20200302.test'162 ]163 for path in paths:164 with open(path, encoding='utf-8') as f:165 for line in f:166 line = line.strip()167 if not line or (line[0] == '=' and line[-1] == '='):168 continue169 yield line170def iterate_naver_changwon_ner(root_dir, force_download, multilingual=False):171 corpus = Korpora.load('naver_changwon_ner', root_dir, force_download)172 for sent in corpus.train.texts:173 yield sent174def iterate_nsmc(root_dir, force_download, multilingual=False):175 corpus = Korpora.load('nsmc', root_dir, force_download)176 for sents in [corpus.train.texts, corpus.test.texts]:177 for sent in sents:178 yield sent179def iterate_question_pair(root_dir, force_download, multilingual=False):180 corpus = Korpora.load('question_pair', root_dir, force_download)181 for sents in [corpus.train.texts, corpus.train.pairs]:182 for sent in sents:183 yield sent184def iterate_open_subtitles(root_dir, force_download, multilingual=False):185 corpus = Korpora.load('open_subtitles', root_dir, force_download)186 for sent in corpus.train.texts:187 yield sent188def iterate_modu_news(root_dir, force_download, multilingual=False):189 corpus = Korpora.load('modu_news', root_dir, force_download)190 for sent in corpus.train.texts:191 yield sent192def iterate_modu_messenger(root_dir, force_download, multilingual=False):193 corpus = Korpora.load('modu_messenger', root_dir, force_download)194 for utt in corpus.train.texts:195 for sent in utt.form:196 yield sent197def iterate_modu_mp(root_dir, force_download, multilingual=False):198 corpus = Korpora.load('modu_mp', root_dir, force_download)199 for mp in corpus.train.texts:200 yield mp.sentence201def iterate_modu_ne(root_dir, force_download, multilingual=False):202 corpus = Korpora.load('modu_ne', root_dir, force_download)203 for sent in corpus.train.texts:204 yield sent.sentence205def iterate_modu_spoken(root_dir, force_download, multilingual=False):206 corpus = Korpora.load('modu_spoken', root_dir, force_download)207 for sent in corpus.train.texts:208 yield sent209def iterate_modu_web(root_dir, force_download, multilingual=False):210 corpus = Korpora.load('modu_web', root_dir, force_download)211 for sent in corpus.train.texts:212 yield sent213def iterate_modu_written(root_dir, force_download, multilingual=False):214 corpus = Korpora.load('modu_written', root_dir, force_download)215 for sent in corpus.train.texts:216 yield sent217def iterate_aihub_translation(corpus_name=''):218 def fn_iterate_aihub_translation(root_dir, force_download, multilingual=False):219 corpus = Korpora.load(corpus_name, root_dir, force_download)220 for sent in corpus.train.texts:221 yield sent222 return fn_iterate_aihub_translation223def iterate_aihub_kspon_speech_scripts(root_dir, force_download, multilingual=False):224 corpus = Korpora.load('aihub_kspon_speech_scripts', root_dir, force_download)225 for sent in corpus.train.texts:226 yield sent.sentence227ITERATE_TEXTS = {228 'kcbert': iterate_kcbert,229 'korean_chatbot_data': iterate_korean_chatbot_data,230 'korean_hate_speech': iterate_korean_hate_speech,231 'korean_parallel_koen_news': iterate_korean_parallel_koen_news,232 'korean_petitions': iterate_korean_petitions,233 'kornli': iterate_kornli,234 'korsts': iterate_korsts,235 'kowikitext': iterate_kowikitext,236 'namuwikitext': iterate_namuwikitext,237 'naver_changwon_ner': iterate_naver_changwon_ner,238 'nsmc': iterate_nsmc,239 'question_pair': iterate_question_pair,240 'open_subtitles': iterate_open_subtitles,241 'modu_news': iterate_modu_news,242 'modu_messenger': iterate_modu_messenger,243 'modu_mp': iterate_modu_mp,244 'modu_ne': iterate_modu_ne,245 'modu_spoken': iterate_modu_spoken,246 'modu_web': iterate_modu_web,247 'modu_written': iterate_modu_written,248 'aihub_spoken_translation': iterate_aihub_translation('aihub_spoken_translation'),249 'aihub_conversation_translation': iterate_aihub_translation('aihub_conversation_translation'),250 'aihub_news_translation': iterate_aihub_translation('aihub_news_translation'),251 'aihub_korean_culture_translation': iterate_aihub_translation('aihub_korean_culture_translation'),252 'aihub_decree_translation': iterate_aihub_translation('aihub_decree_translation'),253 'aihub_government_website_translation': iterate_aihub_translation('aihub_government_website_translation'),254 'aihub_kspon_speech_scripts': iterate_aihub_kspon_speech_scripts,...
OutputInfoFull.py
Source:OutputInfoFull.py
1"""23Robert:4 5 Below is a series of dictionaries which contain the output writing6 information for each quantity in the metadate. In principle, each entry in7 the respective dictionary will determine how that quantity is to be handled.8 9 10 It will be used in the following format during production runs...11 12 import OutputInfo as OI13 14 for x in Metadata.keys():15 try:16 Attrs = getattr(OI, str(x)) 17 #This will get each item's output parameters and use them to determine18 #the correct way to handle the output.19 for attr in Attrs:20 use Attrs[attr] to do something interesting.21 22 23 except Exception as e:24 #Handle the exception as necessary25 26 27 Each dictionary will have elements of the form - 28 29 'Dir' : '', #Where to place the output30 'File' : '', #What to call the file31 'Iterate' : , #Whether to expect to write multiple times32 'Bool' : , #Will quantity be boolean? T - Make empty file, F - No33 'xyz' : , If the quantiy should be available to written into an extended xyz34 'Array' : , #Prepare the write object for each element to be an array35 'Exec' : , #If the quantity is written info for the sysinfo file3637"""3839#########################################################################################40#########################################################################################41#########################################################################################4243masterkey = {44 'Dir' : 'Exec/', 'File' : 'Masterkey', 'Iterate' : False, 'Bool' : False, 45 'xyz' : False, 'array' : True, 'Exec' : False46 }4748base_dir = {49 'Dir' : 'Exec/', 'File' : 'SysInfo', 'Iterate' : False, 'Bool' : False,50 'xyz' : False, 'array' : False, 'Exec' : True51 }5253movie_file_name = {54 'Dir' : 'Exec/', 'File' : 'SysInfo', 'Iterate' : False, 'Bool' : False,55 'xyz' : False, 'array' : False, 'Exec' : True56 }5758energy_file_name = {59 'Dir' : 'Exec/', 'File' : 'SysInfo', 'Iterate' : False, 'Bool' : False, 60 'xyz' : False, 'array' : False, 'Exec' : True61 }6263extend_xyz = {64 'Dir' : 'Exec/', 'File' : 'SysInfo', 'Iterate' : False, 'Bool' : True,65 'xyz' : False, 'array' : True, 'Exec' : True66 }6768Homo = {69 'Dir' : 'Exec/', 'File' : 'SysInfo', 'Iterate' : False, 'Bool' : False,70 'xyz' : False, 'array' : True, 'Exec' : True71 }7273Hetero = {74 'Dir' : 'Exec/', 'File' : 'SysInfo', 'Iterate' : False, 'Bool' : True,75 'xyz' : False, 'array' : False, 'Exec' : True76 }7778Start = {79 'Dir' : 'Exec/', 'File' : 'SysInfo', 'Iterate' : False, 'Bool' : False,80 'xyz' : False, 'array' : False, 'Exec' : True81 }8283End = {84 'Dir' : 'Exec/', 'File' : 'SysInfo', 'Iterate' : False, 'Bool' : False,85 'xyz' : False, 'array' : False, 'Exec' : True86 }8788Step = {89 'Dir' : 'Exec/', 'File' : 'SysInfo', 'Iterate' : False, 'Bool' : False,90 'xyz' : False, 'array' : False, 'Exec' : True91 }9293NFrames = {94 'Dir' : 'Exec/', 'File' : 'SysInfo', 'Iterate' : False, 'Bool' : False,95 'xyz' : False, 'array' : False, 'Exec' : True96 }9798Skip = {99 'Dir' : 'Exec/', 'File' : 'SysInfo', 'Iterate' : False, 'Bool' : False,100 'xyz' : False, 'array' : False, 'Exec' : True101 }102UniformPDF = {103 'Dir' : 'Exec/', 'File' : 'SysInfo', 'Iterate' : False, 'Bool' : False,104 'xyz' : False, 'array' : False, 'Exec' : True105 }106107Band = {108 'Dir' : 'Exec/', 'File' : 'SysInfo', 'Iterate' : False, 'Bool' : False,109 'xyz' : False, 'array' : False, 'Exec' : True110 }111112Species = {113 'Dir' : 'Exec/', 'File' : 'SysInfo', 'Iterate' : False, 'Bool' : False,114 'xyz' : False, 'array' : False, 'Exec' : True115 }116117NSpecies = {118 'Dir' : 'Exec/', 'File' : 'SysInfo', 'Iterate' : False, 'Bool' : False,119 'xyz' : False, 'array' : False, 'Exec' : True120 }121122comspace = {123 'Dir' : 'Exec/', 'File' : 'comspace', 'Iterate' : False, 'Bool' : False,124 'xyz' : False, 'array' : True, 'Exec' : False125 }126127#########################################################################################128#########################################################################################129#########################################################################################130131rcut = {132 'Dir' : 'Time_Dependent/', 'File' : 'RCut', 'Iterate' : True, 'Bool' : False,133 'xyz' : False, 'array' : False, 'Exec' : False134 }135136137moi = {138 'Dir' : 'Time_Dependent/', 'File' : 'MoI', 'Iterate' : True, 'Bool' : False,139 'xyz' : False, 'array' : True, 'Exec' : False140 }141142gyration = {143 'Dir' : 'Time_Dependent/', 'File' : 'Gyration', 'Iterate' : True, 'Bool' : False,144 'xyz' : False, 'array' : False, 'Exec' : False145 }146147stat_radius = {148 'Dir' : 'Time_Dependent/', 'File' : 'Stat_Radius', 'Iterate' : True, 'Bool' : False,149 'xyz' : False, 'array' : False, 'Exec' : False150 }151152surf_area = {153 'Dir' : 'Time_Dependent/', 'File' : 'Surf_Area', 'Iterate' : True, 'Bool' : False,154 'xyz' : False, 'array' : False, 'Exec' : False155 }156157surf_atoms = {158 'Dir' : 'Time_Dependent/', 'File' : 'Surf_Atoms', 'Iterate' : True, 'Bool' : False,159 'xyz' : False, 'array' : False, 'Exec' : False160 }161162com = {163 'Dir' : 'Time_Dependent/', 'File' : 'CoM', 'Iterate' : True, 'Bool' : False,164 'xyz' : False, 'array' : True, 'Exec' : False165 }166167Elements = {168 'Dir' : 'Time_Dependent/', 'File' : 'Elements', 'Iterate' : True, 'Bool' : False,169 'xyz' : False, 'array' : True, 'Exec' : False170 }171172NAtoms = {173 'Dir' : 'Time_Dependent/', 'File' : 'NAtoms', 'Iterate' : True, 'Bool' : False,174 'xyz' : False, 'array' : False, 'Exec' : False175 }176177#########################################################################################178#########################################################################################179#########################################################################################180181"""182183Robert:184 185 Below are the quantities which may be written into an extended xyz file186 if this is requested by the user. 187 188 It is likely that I will set an additional flag in the dictionaries to enable189 this mode to be compatable with the "extend_xyz" logical variable.190 191"""192193194pattern_indices = {195 'Dir' : 'CNA/', 'File' : 'Patterns', 'Iterate' : True, 'Bool' : False,196 'xyz' : True, 'array' : True, 'Exec' : False197 }198199agcn = {200 'Dir' : 'Time_Dependent/', 'File' : 'AGCN', 'Iterate' : True, 'Bool' : False,201 'xyz' : True, 'array' : True, 'Exec' : False202 }203204nn = {205 'Dir' : 'Time_Dependent/', 'File' : 'NN', 'Iterate' : True, 'Bool' : False,206 'xyz' : True, 'array' : True, 'Exec' : False207 }208209#########################################################################################210#########################################################################################211#########################################################################################212213"""214215Robert:216 217 Below are the quantities which require undisclosed array sizes and so are218 likely to be awkward to write as meaningful and useful outputs.219 220"""221222rdf = {223 'Dir' : 'Time_Dependent/', 'File' : 'RDF', 'Iterate' : True, 'Bool' : False,224 'xyz' : False, 'array' : True, 'Exec' : False225 }226227rdfspace = {228 'Dir' : 'Time_Dependent/', 'File' : 'RDFSpace', 'Iterate' : True, 'Bool' : False,229 'xyz' : False, 'array' : True, 'Exec' : False230 }231232cna_sigs = {233 'Dir' : 'CNA/', 'File' : 'Signatures', 'Iterate' : True, 'Bool' : False,234 'xyz' : False, 'array' : True, 'Exec' : False235 }236237adj = {238 'Dir' : 'Adjacency/', 'File' : 'Full', 'Iterate' : True, 'Bool' : False,239 'xyz' : False, 'array' : True, 'Exec' : False240 }241242pdf = {243 'Dir' : 'Time_Dependent/', 'File' : 'PDF', 'Iterate' : True, 'Bool' : False,244 'xyz' : False, 'array' : True, 'Exec' : False245 }246247pdfspace = {248 'Dir' : 'Time_Dependent/', 'File' : 'PDFSpace', 'Iterate' : True, 'Bool' : False,249 'xyz' : False, 'array' : True, 'Exec' : False250 }251252comdist = {253 'Dir' : 'Time_Dependent/', 'File' : 'CoMDist', 'Iterate' : True, 'Bool' : False,254 'xyz' : False, 'array' : True, 'Exec' : False255 }256257pair_distance = {258 'Dir' : 'Time_Dependent/', 'File' : 'PairDistances', 'Iterate' : True, 'Bool' : False,259 'xyz' : False, 'array' : True, 'Exec' : False260 }261262pair_distancespace = {263 'Dir' : 'Time_Dependent/', 'File' : 'PairDistancesSpace', 'Iterate' : True, 'Bool' : False,264 'xyz' : False, 'array' : True, 'Exec' : False
...
Optimized.py
Source:Optimized.py
1## @ingroup Analyses-Mission-Segments-Climb2# Optimized.py3#4# Created: Mar 2016, E. Botero 5# Apr 2020, M. Clarke6# Aug 2021, R. Erhard7# ----------------------------------------------------------------------8# Imports9# ----------------------------------------------------------------------10# SUAVE imports11from SUAVE.Analyses.Mission.Segments import Aerodynamic12from SUAVE.Analyses.Mission.Segments import Conditions13from SUAVE.Methods.Missions import Segments as Methods14from SUAVE.Methods.skip import skip15from SUAVE.Analyses import Process16# Units17from SUAVE.Core import Units18# ----------------------------------------------------------------------19# Segment20# ----------------------------------------------------------------------21## @ingroup Analyses-Mission-Segments-Climb22class Optimized(Aerodynamic):23 """ Optimize your climb segment. This is useful if you're not sure how your vehicle should climb.24 You can set any conditions parameter as the objective, for example setting time to climb or vehicle mass:25 segment.objective = 'conditions.weights.total_mass[-1,0]'26 27 The ending airspeed is an optional parameter.28 29 This segment takes far longer to run than a normal segment. Wrapping this into a vehicle optimization30 has not yet been tested for robustness.31 32 33 Assumptions:34 Can use SNOPT if you have it installed through PyOpt. But defaults to SLSQP through 35 Runs a linear true airspeed mission first to initialize conditions.36 37 Source:38 None39 """ 40 41 def __defaults__(self):42 """ This sets the default solver flow. Anything in here can be modified after initializing a segment.43 44 Assumptions:45 None46 47 Source:48 N/A49 50 Inputs:51 None52 53 Outputs:54 None55 56 Properties Used:57 None58 """ 59 60 # --------------------------------------------------------------61 # User inputs62 # --------------------------------------------------------------63 self.altitude_start = None64 self.altitude_end = None65 self.air_speed_start = None66 self.air_speed_end = None67 self.objective = None # This will be a key68 self.minimize = True69 self.lift_coefficient_limit = 1.e20 70 self.seed_climb_rate = 100. * Units['feet/min']71 self.algorithm = 'SLSQP'72 self.true_course = 0.0 * Units.degrees 73 74 75 # --------------------------------------------------------------76 # State77 # --------------------------------------------------------------78 79 # conditions80 self.state.conditions.update( Conditions.Aerodynamics() )81 # initials and unknowns82 ones_row = self.state.ones_row83 self.state.unknowns.throttle = ones_row(1) * 0.884 self.state.unknowns.body_angle = ones_row(1) * 5.0 * Units.degrees85 self.state.unknowns.flight_path_angle = ones_row(1) * 3.0 * Units.degrees86 self.state.unknowns.velocity = ones_row(1) * 1.087 self.state.residuals.forces = ones_row(2) * 0.088 self.state.inputs_last = None89 self.state.objective_value = 0.090 self.state.constraint_values = 0.091 92 # --------------------------------------------------------------93 # The Solving Process94 # --------------------------------------------------------------95 96 # --------------------------------------------------------------97 # Initialize - before iteration98 # --------------------------------------------------------------99 initialize = self.process.initialize100 initialize.expand_state = Methods.expand_state101 initialize.solved_mission = Methods.Climb.Optimized.solve_linear_speed_constant_rate102 initialize.differentials = Methods.Common.Numerics.initialize_differentials_dimensionless103 initialize.conditions = skip104 # --------------------------------------------------------------105 # Converge - starts iteration106 # --------------------------------------------------------------107 converge = self.process.converge108 109 converge.converge_root = Methods.converge_opt 110 # --------------------------------------------------------------111 # Iterate - this is iterated112 # --------------------------------------------------------------113 iterate = self.process.iterate114 115 # Update Initials116 iterate.initials = Process()117 iterate.initials.time = Methods.Common.Frames.initialize_time118 iterate.initials.weights = Methods.Common.Weights.initialize_weights119 iterate.initials.inertial_position = Methods.Common.Frames.initialize_inertial_position120 iterate.initials.planet_position = Methods.Common.Frames.initialize_planet_position121 122 # Unpack Unknowns123 iterate.unknowns = Process()124 iterate.unknowns.mission = Methods.Climb.Optimized.unpack_unknowns125 126 # Update Conditions127 iterate.conditions = Process()128 iterate.conditions.differentials = Methods.Climb.Optimized.update_differentials129 iterate.conditions.acceleration = Methods.Common.Frames.update_acceleration130 iterate.conditions.altitude = Methods.Common.Aerodynamics.update_altitude131 iterate.conditions.atmosphere = Methods.Common.Aerodynamics.update_atmosphere132 iterate.conditions.gravity = Methods.Common.Weights.update_gravity133 iterate.conditions.freestream = Methods.Common.Aerodynamics.update_freestream134 iterate.conditions.orientations = Methods.Common.Frames.update_orientations 135 iterate.conditions.propulsion = Methods.Common.Energy.update_thrust 136 iterate.conditions.aerodynamics = Methods.Common.Aerodynamics.update_aerodynamics137 iterate.conditions.stability = Methods.Common.Aerodynamics.update_stability138 iterate.conditions.weights = Methods.Common.Weights.update_weights139 iterate.conditions.forces = Methods.Common.Frames.update_forces140 iterate.conditions.planet_position = Methods.Common.Frames.update_planet_position141 # Solve Residuals142 iterate.residuals = Process() 143 iterate.residuals.total_forces = Methods.Climb.Common.residual_total_forces144 145 # Set outputs146 iterate.outputs = Process() 147 iterate.outputs.objective = Methods.Climb.Optimized.objective148 iterate.outputs.constraints = Methods.Climb.Optimized.constraints149 iterate.outputs.cache_inputs = Methods.Climb.Optimized.cache_inputs150 151 # --------------------------------------------------------------152 # Finalize - after iteration153 # --------------------------------------------------------------154 finalize = self.process.finalize155 156 # Post Processing157 finalize.post_process = Process() 158 finalize.post_process.inertial_position = Methods.Common.Frames.integrate_inertial_horizontal_position159 finalize.post_process.stability = Methods.Common.Aerodynamics.update_stability160 finalize.post_process.aero_derivatives = skip161 finalize.post_process.noise = Methods.Common.Noise.compute_noise162 ...
Aerodynamic.py
Source:Aerodynamic.py
1## @ingroup Analyses-Mission-Segments2# Aerodynamic.py3#4# Created: 5# Modified: Feb 2016, Andrew Wendorff6# ----------------------------------------------------------------------7# Imports8# ----------------------------------------------------------------------9# SUAVE imports10from SUAVE.Analyses.Mission.Segments import Simple11from SUAVE.Analyses.Mission.Segments import Conditions 12from SUAVE.Methods.Missions import Segments as Methods 13from SUAVE.Methods.skip import skip14from SUAVE.Analyses import Process15# ----------------------------------------------------------------------16# Segment17# ----------------------------------------------------------------------18## @ingroup Analyses-Mission-Segments19class Aerodynamic(Simple):20 """ The third basic piece of a mission which each segment will expand upon21 22 Assumptions:23 There's a detailed process flow outline in defaults. A mission must be solved in that order.24 Assumes you're an atmospheric vehicle.25 26 Source:27 None28 """ 29 30 def __defaults__(self):31 """This sets the default values.32 33 Assumptions:34 None35 36 Source:37 N/A38 39 Inputs:40 None41 42 Outputs:43 None44 45 Properties Used:46 None47 """ 48 49 # --------------------------------------------------------------50 # User inputs51 # --------------------------------------------------------------52 # self.example = 1.053 54 55 # --------------------------------------------------------------56 # State57 # --------------------------------------------------------------58 59 # conditions60 self.state.conditions.update( Conditions.Aerodynamics() )61 self.temperature_deviation = 0.062 63 # --------------------------------------------------------------64 # The Solving Process65 # --------------------------------------------------------------66 67 # --------------------------------------------------------------68 # Initialize - before iteration69 # --------------------------------------------------------------70 initialize = self.process.initialize71 72 initialize.expand_state = Methods.expand_state73 initialize.differentials = Methods.Common.Numerics.initialize_differentials_dimensionless74 initialize.conditions = None 75 76 # --------------------------------------------------------------77 # Converge - starts iteration78 # --------------------------------------------------------------79 converge = self.process.converge80 81 converge.converge_root = Methods.converge_root 82 83 # --------------------------------------------------------------84 # Iterate - this is iterated85 # --------------------------------------------------------------86 iterate = self.process.iterate87 # Update Initials88 iterate.initials = Process()89 iterate.initials.time = Methods.Common.Frames.initialize_time90 iterate.initials.weights = Methods.Common.Weights.initialize_weights91 iterate.initials.inertial_position = Methods.Common.Frames.initialize_inertial_position92 iterate.initials.planet_position = Methods.Common.Frames.initialize_planet_position93 94 # Unpack Unknowns95 iterate.unknowns = Process()96 iterate.unknowns.mission = None 97 98 # Update Conditions99 iterate.conditions = Process()100 iterate.conditions.differentials = Methods.Common.Numerics.update_differentials_time 101 iterate.conditions.altitude = Methods.Common.Aerodynamics.update_altitude102 iterate.conditions.atmosphere = Methods.Common.Aerodynamics.update_atmosphere103 iterate.conditions.gravity = Methods.Common.Weights.update_gravity104 iterate.conditions.freestream = Methods.Common.Aerodynamics.update_freestream105 iterate.conditions.orientations = Methods.Common.Frames.update_orientations106 iterate.conditions.aerodynamics = Methods.Common.Aerodynamics.update_aerodynamics107 iterate.conditions.stability = Methods.Common.Aerodynamics.update_stability108 iterate.conditions.energy = Methods.Common.Energy.update_thrust109 iterate.conditions.weights = Methods.Common.Weights.update_weights110 iterate.conditions.forces = Methods.Common.Frames.update_forces111 iterate.conditions.planet_position = Methods.Common.Frames.update_planet_position112 # Solve Residuals113 iterate.residuals = Process()114 # --------------------------------------------------------------115 # Finalize - after iteration116 # --------------------------------------------------------------117 finalize = self.process.finalize118 119 # Post Processing120 finalize.post_process = Process() 121 finalize.post_process.inertial_position = Methods.Common.Frames.integrate_inertial_horizontal_position122 finalize.post_process.stability = Methods.Common.Aerodynamics.update_stability123 finalize.post_process.aero_derivatives = skip124 finalize.post_process.noise = Methods.Common.Noise.compute_noise125 ...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!