PowerModels power flow

Hello,

I am using PowerModels to analyse the power flow of a network.

Why is the voltage angle different from the results obtained by MATPOWER tools in MATLAB.
I am using this line to calculate the optimal power flow.

result = run_opf("case9.m", ACPPowerModel, with_optimizer(Ipopt.Optimizer))

Thank you

Hi @hmemy, thanks for trying out PowerModels! Could you provide a little more details about how the solutions differ (e.g. is it in the objective value, voltage profile, generator dispatch) and also what commands you are running in Matpower to compare?

This paper is the last time I did a side-by-side comparison was in this paper, https://arxiv.org/abs/1711.01728, at that time, the solutions of AC Power Flow were identical or nearly so.

3 Likes

Hi @ccoffrin,

I have figured it out. It is just MATPOWER’s is in degrees and PowerModels is in rad.

Another question,
savecase function is utilised In MATPOWER to create a new case file. How can I create a new case file in PowerModels?

Note/ I have already looked at your paper. Great work !

Great! I am glad to hear it.

That is good point that I forgot about! By default PowerModels works in the per_unit convention for its data, while Matpower uses a mixed units convention. You can use make_mixed_units! to turn the PowerModels data into Matpower’s unit convention, but you will have to turn it back with make_per_unit! before using it again in PowerModels.

In terms of saving data, you can try the export_matpower function. It is well tested but the results might look a little different than a pure Matpower case file becouse PowerModels supports a more general model of the network components.

1 Like

Hello @ccoffrin, I hope you are well.

I have created new data dictionaries named: new_bus, new_gen, new_branch, and I would like to save them in a file order to run an optimal power flow analysis. Could you please explain how to achieve this? Many thanks!

With the HDF5 package you can save *.jld files, the equivalent of *.mat files for Julia.

1 Like

Hi @martincornejo, is the saved file readable in PowerModels?

If you have created a dictionary network_data that contains all the necessary data in the PowerModels format you don’t need to save it for PowerModels to read it, you can simply feed it directly. Take this example taken from the documentation

# network_data is your dictionary with bus, branch and gen data

pm = instantiate_model(network_data, ACPPowerModel, PowerModels.build_opf)

print(pm.model)

result = optimize_model!(pm, optimizer=with_optimizer(Ipopt.Optimizer))

If for some reason you would like to save the dictionary network_data to work later on it, or send it to a colleague you could save it into a julia data file (*.jld). As for the instantiated model pm I’m not sure how you could save it, but I think it should be possible.

1 Like

I will give it a try. Thank you

@hmemy, you can also try the export_matpower function provided in PowerModels. Know that you might see some extra data tables in there because PowerModels supports a more general network model than Matpower. That said, if you restrict your self to the Matpower subset, it should work as expected.

Also for general information, I generally think about PowerModels data dicts as an internal data model, but they are JSON serializable. This is quite helpful when building multi-language pipelines.

1 Like

hello, ccoffrin, I’m a new to learn PowerModels and Julia, can you tell me how to use “export_matpower” function?
thanks!

I have known it, thank you for your useful reply.

Hello, @ccoffrin, now I am using export_matpower, the m file show the result, but
there are too many digits after the decimal point.
When I use print_summary, display in repl doesn’t have so many digits.
can I set the number of digits in export_matpower function?

There is no feature to truncate the accuracy of export_matpower and I would generally not encourage this as solutions can easily be sensitive to the 7th decimal place in the voltage magnitude values.

You could do some pre-processing on the PowerModels data dictionary to truncate the data values before calling export_matpower and this should have the effect you are looking for.

Thank you very much @ccoffrin .
Now I am studying SOC-OPF in PowerModelsAnnex, the program have calculated W value, but I can’t find the function calculates V value using W.
Looking forward to your reply!

I think what you are looking for is the solution processor called sol_data_model!, have a look at this example,

Yes, that is the model I want.
But when I see the definition of sol_data_model!,I only find the solution of ‘vm’ in function _sol_data_model_w!(solution::Dict)

You know the SOC-OPF result gives ‘w’ 、‘wr’、‘wi’, atan(wi/wr) only gets the angle between vi and vj, but they are not the angle relative to the reference bus, I want to know how to compute the ‘va’ in sol_data_model!
looking forwar your reply, thank you very much.

@Xuekui_wang in general it is not possible to map the wr wi values into va values, this is because wr wi are a higher dimension (|E|) than the va values (|N|), this is part of the reason with SOC-OPF is a relaxation and not an exact solution. So this is not supported by PowerModels by default.

Yes, thank you ccoffrin, I think I have known it.
If I want the result of va,the power flow can be used based on SOC result of “Pg”.

Yes, that is a reasonable approach to recover an AC feasible solution.