ucd-cws / calvin

reservoir network optimization
MIT License
21 stars 13 forks source link

Getting rid of debug flows and running w/o debug mode #29

Closed msdogan closed 7 years ago

msdogan commented 7 years ago

My latest one-year run (Oct 2002 - Sep 2003) had some debug flows. But results are promising. It occurred in a few places and the problem seems to end-of-period storage problem for reservoirs. One debug flow on SR_BUL is quite big, others are small. I am just creating this issue. I need to run 82-year model and make calibration on that run not 1 year if needed. Since CALVIN and Hobbes test could be run w/o debug mode, we need to take a closer look what is causing it before modifying fixed time-series and minimum in-stream flow requirements.

1-year run debug flows:

Link: DBUGSRC-SR_BUL, Time: 2003-09-30, Flow: 165.997728
Link: DBUGSRC-SR_CLE, Time: 2003-09-30, Flow: 1.42277304048493
Link: DBUGSRC-SR_CR1, Time: 2003-09-30, Flow: 0.00999999977648258
Link: DBUGSRC-SR_CR2, Time: 2003-09-30, Flow: 0.00999999977648258
Link: DBUGSRC-SR_HTH, Time: 2003-09-30, Flow: 0.869099103516036
jdherman commented 7 years ago

Ok great! At least we know it runs without errors now. Let's see what comes up for the 82-year version and we'll try to figure out what's missing.

msdogan commented 7 years ago

Yes, it runs without errors for 1 year but not for other periods :) I posted a new issue https://github.com/ucd-cws/calvin-network-tools/issues/42 Hopefully we won't get to many debug flow links when we run 82-year.

msdogan commented 7 years ago

@jdherman @jrmerz some good news! I run Pyvin without debug mode for a time period of 82 years and got a feasible solution. It took 88 seconds of solver time and 1654 seconds (27 min) of total computing time.

Now we can compare results to CALVIN and HOBBES test.

Barrier solved model.

Dual simplex - Optimal:  Objective = -4.0676283943e+10
Solution time =   88.80 sec.  Iterations = 4626 (2444)
Deterministic time = 73402.44 ticks  (826.63 ticks/sec)

CPLEX> Solution written to file '/tmp/tmpt4hgg_ss.cplex.sol'.
CPLEX> [ 1378.36] Processing results
    Number of solutions: 1
    Solution Information
      Gap: 0.0
      Status: optimal
      Function Value: -40676283943.10019
    Solver results file: results.json
[ 1654.24] Applying Pyomo postprocessing actions
[ 1654.24] Pyomo Finished
jrmerz commented 7 years ago

Awesome!!!

jdherman commented 7 years ago

oh yea :sunglasses:

that's great news! Now we can try out Max's postprocessors. Let's talk about this tomorrow if anyone's around.

msdogan commented 7 years ago

sounds good

msdogan commented 7 years ago

After Justin's updates for the new matrix format and fixes for MIF links that do not have a cost, I run the model (82-year) without debug mode but the solution got infeasible, so I run in debug mode and here are debug flows. Small flow amounts but enough to make the solution infeasible.

Link: C18-DBUGSNK, Time: 2000-12-31, Flow: 1e-06
Link: DBUGSRC-N201, Time: 1924-09-30, Flow: 0.01931791186052756
Link: DBUGSRC-N201, Time: 1931-10-31, Flow: 0.0003588662482307825
Link: DBUGSRC-N201, Time: 1988-08-31, Flow: 0.036107923837622735
Link: DBUGSRC-N201, Time: 1988-10-31, Flow: 0.0003578662482306427
Link: DBUGSRC-SR_GNT, Time: 1948-04-30, Flow: 0.038725496962414674
Link: DBUGSRC-SR_GNT, Time: 1955-04-30, Flow: 0.03436905715971994
Link: DBUGSRC-SR_GNT, Time: 1978-03-31, Flow: 0.18396324513581153
Link: DBUGSRC-SR_RLL_CMB, Time: 1924-10-31, Flow: 0.0003578662482306427
Link: DBUGSRC-SR_RLL_CMB, Time: 1931-09-30, Flow: 0.024019490745414984
Link: DBUGSRC-SR_RLL_CMB, Time: 1988-09-30, Flow: 0.0004341997355741256
Link: HSD203-DBUGSNK, Time: 1925-12-31, Flow: 1e-06
Link: HSD203-DBUGSNK, Time: 1997-12-31, Flow: 1e-06
Link: WWP402-DBUGSNK, Time: 2000-01-31, Flow: 1e-06
jdherman commented 7 years ago

Thanks Mustafa. Ok no big deal -- these are REALLY small, just numerical noise.

What is the usual process for fixing debug flows? Add more inflow somewhere?

msdogan commented 7 years ago

Yeah there are two options: 1) Inject small flow to origin node of problematic links, 2) Find lower or upper bound constraint that causes mass balance problem and reduce it.

In the past, I chose the second option first. For this case, flow amounts are very small, so injecting small inflows mights be okay?

jdherman commented 7 years ago

Sounds like option (1) would require adding new links, right? That could get confusing later.

With (2) we could just slightly modify the constraints by a few decimal places, although I'm not sure whether to increase or decrease them. But that sounds better to me.

msdogan commented 7 years ago

Yes, option 1 requires adding new links. However, N201 is upstream of SR_RLL_CMB and we already have a calibration link (CN2) that inject flow.

For option 2, this can be a little tricky because the model does not always put debug flows in the same place and time where the mass balance problem occurs. It can put very upstream reservoir to get some hydropower benefit, or in a previous time-period to reduce scarcity somewhere else. I had this problem a lot when I was dealing with debug flows, which was much greater than this. And then, I decided to use dual values on constraints. It gives the precise time and location. If it is a debug source, we need to reduce the constraint and opposite for debug sink.

We can discuss this in more detail in our first meeting.

jdherman commented 7 years ago

Ok, got it. Either one is fine with me since it won't have any affect on the output.

msdogan commented 7 years ago

Here are debug flows after updating decimal places on input parameters (https://github.com/ucd-cws/calvin-network-tools/issues/48). We got rid of some noise, but there is still some to eliminate. Note: I haven't done anything, this is just after running with new decimal places.

Link: DBUGSRC-N201, Time: 1924-09-30, Flow: 0.022365432685755415
Link: DBUGSRC-N201, Time: 1931-10-31, Flow: 0.0018744477468057852
Link: DBUGSRC-N201, Time: 1988-09-30, Flow: 0.0005010300782868349
Link: DBUGSRC-N201, Time: 1988-10-31, Flow: 0.0008744477468054512
Link: DBUGSRC-SR_GNT, Time: 1948-04-30, Flow: 0.04043407809307542
Link: DBUGSRC-SR_GNT, Time: 1955-04-30, Flow: 0.035512803545655114
Link: DBUGSRC-SR_GNT, Time: 1978-03-31, Flow: 0.17911455385713015
Link: DBUGSRC-SR_RLL_CMB, Time: 1931-09-30, Flow: 0.025860218859669715
Link: DBUGSRC-SR_RLL_CMB, Time: 1988-08-31, Flow: 0.04098622248936756
msdogan commented 7 years ago

@jdherman @mimijenkins1 for Bear river watershed (N201, SR_RLL_CMB), I used the existing calibration link to inject small flow amounts above.

Here are debug after adding infeasibility flows for N201 and SR_RLL_CMB.

Link: DBUGSRC-N201, Time: 1924-09-30, Flow: 0.00036543268575517374
Link: DBUGSRC-SR_GNT, Time: 1948-04-30, Flow: 0.04043407809307542
Link: DBUGSRC-SR_GNT, Time: 1955-04-30, Flow: 0.035512803545655114
Link: DBUGSRC-SR_GNT, Time: 1978-03-31, Flow: 0.17911455385713015

Now, we have debug flows for the 82-year run only for 4 locations/time-steps. I will add debug flow amount for DBUGSRC-N201 to existing link (CN2-N201).

For DBUGSRC-SR_GNT, however, we do not have a calibration link. I couldn't find which MIF or constrained flow is causing mass balance problem. I was wondering if it is okay to add these small debug flows to existing Mono Basin rim inflows since they are very small.

The schematic shows Mono basin and green dots represent minimum in-stream if storage requirements.

capture

Update: I found what is causing the problem. It was minimum in-stream flow requirements on SR_GNT-SR_ML. I reduced it for debug flow amounts and created another run. I will post the results.

msdogan commented 7 years ago

closing this issue. all debug flows are eliminated and pyvin can be run without debug mode

jdherman commented 7 years ago

Woohoo!! 🚀

msdogan commented 7 years ago

:)

In summary what I did is:

mimijenkins1 commented 7 years ago

Yup! Well done Mustafa and team. A great milestone. Mimi On Mon, 09 Jan 2017 16:21:30 -0800, Jon Herman notifications@github.com
wrote:

Woohoo!! 🚀

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

-- Marion W. Jenkins, PhD Research Engineer Dept. Civil & Environmental Engineering Ghausi Hall, Rm 3019 University of California at Davis Davis, CA 95616

josue-medellin commented 7 years ago

Mustafa, this is great news. This has moved CALVIN into new era. Thanks for your diligent work.

Kind regards,

Josue

On Mon, Jan 9, 2017 at 4:46 PM, mimijenkins1 notifications@github.com wrote:

Yup! Well done Mustafa and team. A great milestone. Mimi On Mon, 09 Jan 2017 16:21:30 -0800, Jon Herman notifications@github.com wrote:

Woohoo!! 🚀

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

-- Marion W. Jenkins, PhD Research Engineer Dept. Civil & Environmental Engineering Ghausi Hall, Rm 3019 University of California at Davis Davis, CA 95616

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/msdogan/pyvin/issues/29#issuecomment-271453976, or mute the thread https://github.com/notifications/unsubscribe-auth/ANGlbKwXDHkvgnTrEVrG-M2zRsBSE66Tks5rQtThgaJpZM4KwTsJ .

-- Josué Medellín-Azuara, Ph.D. Associate Research Engineer Department of Civil and Environmental Engineering Center for Watershed Sciences University of California, Davis One Shields Ave. Davis, CA 95616 Mobile: + 1 530 574 8019 Website: http://watershed.ucdavis.edu/medellin

Convener California Water and Environmental Modeling Forum, CWEMF http://cwemf.org

Be green! Please don't print this e-mail unless you really need to.

jrmerz commented 7 years ago

Yes! +1 +1