Package: matpower
matpower-pipMakeMATPOWERinstallable frompypi. This package makeMATPOWERcopy (currently Version7.1) aspython package. Use this package withmypower(the recommended way) oroct2pyto runMATPOWERusing octave client.matlab.engineis also supported. For the latest docs, readREADME on GitHub.This project also listed onrelated linkson matpower official website. Please visit that site to find other useful resources.InstallationmatpowerFor downloadingMATPOWERonly (maybe you will run it usingmatlab.engineor any other method, or simply want an easyMATPOWERdownloader):pip install matpoweroct2py(Windows)For callablematpowerviaoct2py(require octave on environment systemPATH):Downloadoctave.Install octave, write down the destination path.Open Environment Variable. You can access it by pressingWindows-Key, typeedit the system environment variables, and pressEnterto search.Add new Environment Variable to executeoctave-cli. The path is likely to beC:\Program Files\octave-5.2.0-w64\mingw64\bin\octave-cli.exe.Variable name:OCTAVE_EXECUTABLEVariable value:location:\\of\\octave\\bin\\octave-cli.exeRestart computer to makeos.environrecognize the new path.Installmatpowerthat includeoct2py.pip install matpower[octave]UsageSeenotebooks/for complete examples. All examples should be compatible with Google ColabRunning with engine (requireoct2pyormatlab.engine)Ifoct2pyormatlab.engineis installed,matpower.start_instancecan be used to runoctaveorMATLABwithMATPOWERpath added. Default engine isoctave. You also can usemypowerfor added functionality as shown inmypower tutorial.frommatpowerimportstart_instancem=start_instance()m.runpf()frommatpowerimportstart_instancem=start_instance()mpc=m.eval('case9',verbose=False)mpc=m.runpf(mpc)frommatpowerimportMatpowerwithMatpower(engine='octave')asm:# run as context managermpc=m.eval('case9',verbose=False)mpc=m.runpf(mpc)print(m._engineisNone)# engine cleanly terminatedfrommatpowerimportpath_matpowerprint(path_matpower)# matpower installation locationSincempc = m.runopf()will makempccontain unsupported<object opf_model>, we can avoid it by request maximum number of outputs usingnout='max_nout'inoctave.frommatpowerimportstart_instancem=start_instance()mpc=m.loadcase('case9')mpopt=m.mpoption('verbose',2)[baseMVA,bus,gen,gencost,branch,f,success,et]=m.runopf(mpc,mpopt,nout='max_nout')Alternatively, it would be better to not parse back value that will not be use on python usingoct2py.evalmethod. Use;to avoid octave print output on running the command.# import start_instance to start matpower instancefrommatpowerimportstart_instance# start instancem=start_instance()# use octave native to run some commandsm.eval("mpopt = mpoption('verbose', 2);")m.eval("mpc = loadcase('case9');")m.eval("r1 = runopf(mpc, mpopt);")# we avoid parse `r1` that containts unsupported `<object opf_model>`# fech data to python (.eval is used because .pull is not working in acessing field)r1_mpc={}r1_mpc['baseMVA']=m.eval('r1.baseMVA;')r1_mpc['version']=m.eval('r1.version;')r1_mpc['bus']=m.eval('r1.bus;')r1_mpc['gen']=m.eval('r1.gen;')r1_mpc['branch']=m.eval('r1.branch;')r1_mpc['gencost']=m.eval('r1.gencost;')# modify variable if necessary[GEN_BUS,PG,QG,QMAX,QMIN,VG,MBASE,GEN_STATUS,PMAX,PMIN,MU_PMAX,MU_PMIN,MU_QMAX,MU_QMIN,PC1,PC2,QC1MIN,QC1MAX,QC2MIN,QC2MAX,RAMP_AGC,RAMP_10,RAMP_30,RAMP_Q,APF]=m.idx_gen(nout='max_nout')gen_index=2# index of generator to be changedgen_index_=int(gen_index-1)# -1 due to python indexing start from 0PMAX_=int(PMAX-1)# -1 due to python indexing start from 0r1_mpc['gen'][gen_index_,PMAX_]=110# in this example, we modify PMAX to be 110[PQ,PV,REF,NONE,BUS_I,BUS_TYPE,PD,QD,GS,BS,BUS_AREA,VM,VA,BASE_KV,ZONE,VMAX,VMIN,LAM_P,LAM_Q,MU_VMAX,MU_VMIN]=m.idx_bus(nout='max_nout')bus_index=7# index of bus to be changedbus_index_=int(bus_index-1)# -1 due to python indexing start from 0PD_=int(PD-1)# -1 due to python indexing start from 0r1_mpc['bus'][bus_index_,int(PD-1)]=80# in this example, we modify PD to be 150# push back value to octave clientm.push('mpc',r1_mpc)# push r1_mpc in python to mpc in octave# test if we can retrive pushed valuempc=m.pull('mpc')# test if our pushed variable can be usedm.eval("r1 = runopf(mpc, mpopt);")Also support usingmatlab.engine.frommatpowerimportstart_instancem=start_instance(engine='matlab')# specify using `matlab.engine` instead of `oct2py`mpc=m.runpf('case5',nargout=0)Known engine issueOctavem.runopf()will makempccontain unsupported<object opf_model>. See:https://github.com/MATPOWER/matpower/issues/134#issuecomment-1007798733Impacted case:r1=m.runopf(mpc)Solution:m.push('mpc',mpc)m.eval("r1 = runopf(mpc, mpopt);")r1_mpc={}r1_mpc['baseMVA']=m.eval('r1.baseMVA;')r1_mpc['version']=m.eval('r1.version;')r1_mpc['bus']=m.eval('r1.bus;')r1_mpc['gen']=m.eval('r1.gen;')r1_mpc['branch']=m.eval('r1.branch;')r1_mpc['gencost']=m.eval('r1.gencost;')VersioningThis package maintainMATPOWERversion with added version mark, i.e.MATPOWER 7.1become7.1.0.x.x.xwhere.x.x.xcome frommatpower-pipversioning. Thematpower-pipversioning is not released onpypisincematpower-pipis restricted for development only (and development should use git instead).TODOcondaanddockerinstallation that include octave-cli installation.AuthorsMuhammad Yasirroni-yasirroniCiteWe do request that publications derived from the use ofmatpower-pipexplicitly acknowledge that fact by including all relatedMATPOWER publicationand the following citation:M. Yasirroni, Sarjiya, "matpower-pip: Make MATPOWER installable from pypi", GitHub, 2021. [Online]. Available:https://github.com/yasirroni/matpower-pip.If a journal publication from the author to appear soon should be cited instead.ContributingSee theCONTRIBUTING.md.AcknowledgementThis repository was supported by theFaculty of Engineering, Universitas Gadjah Madaunder the supervision ofMr. Sarjiya. If you use this package, we are very glad if you cite any relevant publication under Mr. Sarjiya's name that can be found on thesemantic scholarorIEEEfor the meantime, since publication related to this repository is ongoing. This work is also partly motivated after I found out thatoct2pysupports runningoctaveclient frompython, but the only implementation for runningMATPOWERthat I know, that isoct2pypower, requiresdockerand is not newbie-friendly. Nevertheless, I would like to say thank you to all people who contributed tooct2py,oct2pypower, and more importantlyMATPOWER.