{"action":"created","issue":{"url":"https://api.github.com/repos/convexopt/gpkit/issues/274","labels_url":"https://api.github.com/repos/convexopt/gpkit/issues/274/labels{/name}","comments_url":"https://api.github.com/repos/convexopt/gpkit/issues/274/comments","events_url":"https://api.github.com/repos/convexopt/gpkit/issues/274/events","html_url":"https://github.com/convexopt/gpkit/issues/274","id":85586813,"number":274,"title":"SP heuristic finds incorrect optimum for simple SP","user":{"login":"pgkirsch","id":8702579,"avatar_url":"https://avatars.githubusercontent.com/u/8702579?v=3","gravatar_id":"","url":"https://api.github.com/users/pgkirsch","html_url":"https://github.com/pgkirsch","followers_url":"https://api.github.com/users/pgkirsch/followers","following_url":"https://api.github.com/users/pgkirsch/following{/other_user}","gists_url":"https://api.github.com/users/pgkirsch/gists{/gist_id}","starred_url":"https://api.github.com/users/pgkirsch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pgkirsch/subscriptions","organizations_url":"https://api.github.com/users/pgkirsch/orgs","repos_url":"https://api.github.com/users/pgkirsch/repos","events_url":"https://api.github.com/users/pgkirsch/events{/privacy}","received_events_url":"https://api.github.com/users/pgkirsch/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"pgkirsch","id":8702579,"avatar_url":"https://avatars.githubusercontent.com/u/8702579?v=3","gravatar_id":"","url":"https://api.github.com/users/pgkirsch","html_url":"https://github.com/pgkirsch","followers_url":"https://api.github.com/users/pgkirsch/followers","following_url":"https://api.github.com/users/pgkirsch/following{/other_user}","gists_url":"https://api.github.com/users/pgkirsch/gists{/gist_id}","starred_url":"https://api.github.com/users/pgkirsch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pgkirsch/subscriptions","organizations_url":"https://api.github.com/users/pgkirsch/orgs","repos_url":"https://api.github.com/users/pgkirsch/repos","events_url":"https://api.github.com/users/pgkirsch/events{/privacy}","received_events_url":"https://api.github.com/users/pgkirsch/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/convexopt/gpkit/milestones/3","html_url":"https://github.com/convexopt/gpkit/milestones/0.3%20-%20Model,%20GP%20refactor,%20SP%20basics","labels_url":"https://api.github.com/repos/convexopt/gpkit/milestones/3/labels","id":1213245,"number":3,"title":"0.3 - Model, GP refactor, SP basics","description":"Model refactor\r\n  - composing Models, creating Model objects (no inheritance!)\r\n       - forms spec for NomialData refactor to follow\r\n\r\nGP refactor\r\n  - emphasize readability of code, especially for mathematicians and solver-writers\r\n\r\nSP basic functionality\r\n  - All SPs should work, but may need initial conditions","creator":{"login":"bqpd","id":1482776,"avatar_url":"https://avatars.githubusercontent.com/u/1482776?v=3","gravatar_id":"","url":"https://api.github.com/users/bqpd","html_url":"https://github.com/bqpd","followers_url":"https://api.github.com/users/bqpd/followers","following_url":"https://api.github.com/users/bqpd/following{/other_user}","gists_url":"https://api.github.com/users/bqpd/gists{/gist_id}","starred_url":"https://api.github.com/users/bqpd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bqpd/subscriptions","organizations_url":"https://api.github.com/users/bqpd/orgs","repos_url":"https://api.github.com/users/bqpd/repos","events_url":"https://api.github.com/users/bqpd/events{/privacy}","received_events_url":"https://api.github.com/users/bqpd/received_events","type":"User","site_admin":false},"open_issues":6,"closed_issues":25,"state":"open","created_at":"2015-07-17T17:00:25Z","updated_at":"2015-08-12T21:15:01Z","due_on":"2015-08-13T04:00:00Z","closed_at":null},"comments":37,"created_at":"2015-06-05T17:25:07Z","updated_at":"2015-08-13T05:27:34Z","closed_at":null,"body":"This example should solve to an optimum at x = 1, y = 1.\r\n\r\n```\r\nimport gpkit\r\nfrom gpkit.shortcuts import *\r\n\r\ngpkit.enable_signomials() \r\n\r\nx = Var('x')\r\ny = Var('y')\r\n\r\nJ = 0.01*((x - 1)**2 + (y - 1)**2) + (x*y - 1)**2\r\n\r\nsp = SP(J)\r\nprint sp\r\nsol = sp.localsolve(x0={x: 1.1, y: 1.1})\r\n\r\nprint sol.table()\r\n\r\ngpkit.disable_signomials()\r\n```\r\n\r\nOutput: \r\n```\r\nIn [1]: %run Mike_SP2.py\r\nOptional Python units library (Pint) not installed;unit support disabled.\r\ngpkit.GeometricProgram( # minimize\r\n          -0.02*x + -0.02*y + -2*x*y + 0.01*x**2 + 0.01*y**2 + 1 + x**2*y**2,\r\n          [   # subject to\r\n          ],\r\n          substitutions={  },\r\n          solver=\"mosek\")\r\nBeginning signomial solve.\r\nUsing solver 'mosek'\r\nSolving for 2 variables.\r\nSolving took 0.159 seconds.\r\nSolving took 5 GP solves.\r\n\r\nCost\r\n 0.624   \r\n\r\nVariables\r\n---------\r\nx : 0.789   \r\ny : 0.789   \r\n\r\nConstant sensitivities\r\n----------------------\r\n```\r\nPossibly related issue: when we `print sp` it outputs `-0.02*x + -0.02*y + -2*x*y + 0.01*x**2 + 0.01*y**2 + 1 + x**2*y**2`. Notice that the constant term should be `1.02` instead of `1`."},"comment":{"url":"https://api.github.com/repos/convexopt/gpkit/issues/comments/130540200","html_url":"https://github.com/convexopt/gpkit/issues/274#issuecomment-130540200","issue_url":"https://api.github.com/repos/convexopt/gpkit/issues/274","id":130540200,"user":{"login":"pgkirsch","id":8702579,"avatar_url":"https://avatars.githubusercontent.com/u/8702579?v=3","gravatar_id":"","url":"https://api.github.com/users/pgkirsch","html_url":"https://github.com/pgkirsch","followers_url":"https://api.github.com/users/pgkirsch/followers","following_url":"https://api.github.com/users/pgkirsch/following{/other_user}","gists_url":"https://api.github.com/users/pgkirsch/gists{/gist_id}","starred_url":"https://api.github.com/users/pgkirsch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pgkirsch/subscriptions","organizations_url":"https://api.github.com/users/pgkirsch/orgs","repos_url":"https://api.github.com/users/pgkirsch/repos","events_url":"https://api.github.com/users/pgkirsch/events{/privacy}","received_events_url":"https://api.github.com/users/pgkirsch/received_events","type":"User","site_admin":false},"created_at":"2015-08-13T05:27:34Z","updated_at":"2015-08-13T05:27:34Z","body":"This might be a separate issue, but I thought this was interesting\r\n\r\n```\r\nimport gpkit\r\nfrom gpkit import Model, Variable\r\nwith gpkit.EnableSignomials():\r\n    x = Variable('x')\r\n    z = Variable('z')\r\n    J = 0.01*(x - 1)**2\r\n    sp = Model(z, [z >= J])\r\n    sol = sp.localsolve(iteration_limit=50)\r\n\r\n\r\n#output\r\n\r\nBeginning signomial solve.\r\n{x: 0.099503719020998152, z: 0.0094544313448217156}\r\n{x: 0.30858339675657204, z: 0.0070641292715984388}\r\n{x: 0.55138385186126571, z: 0.004137253654887871}\r\n{x: 0.7558555212372341, z: 0.0020329156059758929}\r\n{x: 0.88772160560639424, z: 0.0008742012957197896}\r\n{x: 0.95412334675043098, z: 0.00034540249534560776}\r\n{x: 0.98237655634014498, z: 0.00013081534457576836}\r\n{x: 0.99340766018349569, z: 4.86639535899045e-05}\r\n{x: 0.99755961776297863, z: 1.7977255827085814e-05}\r\n{x: 0.99910015431588806, z: 6.6236742434287643e-06}\r\n{x: 0.99966868273464993, z: 2.4381000785678302e-06}\r\n{x: 0.99987807689494357, z: 8.9711476347932211e-07}\r\n{x: 0.99995514181077461, z: 3.3005551447630321e-07}\r\n{x: 0.9999834968924961, z: 1.2142408125806915e-07}\r\n{x: 0.99999392875103243, z: 4.4669889151738637e-08}\r\n{x: 0.99999776649946515, z: 1.6433196923939157e-08}\r\n{x: 0.99999917833933127, z: 6.0454438375448823e-09}\r\n{x: 0.9999996977276967, z: 2.2239956551815462e-09}\r\n{x: 0.99999988880020207, z: 8.1816243629095626e-10}\r\n{x: 0.99999995909187633, z: 3.0098516157414271e-10}\r\n{x: 0.9999999849507416, z: 1.1072625650178e-10}\r\n{x: 0.99999999446368726, z: 4.0733912983436912e-11}\r\n{x: 1.0, z: 1.0, \\fbox{0}: 1.0}\r\n{x: 0.099503719020998152, z: 0.0094544313448217156}\r\n{x: 0.30858339675657204, z: 0.0070641292715984388}\r\n{x: 0.55138385186126571, z: 0.004137253654887871}\r\n{x: 0.7558555212372341, z: 0.0020329156059758929}\r\n{x: 0.88772160560639424, z: 0.0008742012957197896}\r\n{x: 0.95412334675043098, z: 0.00034540249534560776}\r\n{x: 0.98237655634014498, z: 0.00013081534457576836}\r\n{x: 0.99340766018349569, z: 4.86639535899045e-05}\r\n{x: 0.99755961776297863, z: 1.7977255827085814e-05}\r\n{x: 0.99910015431588806, z: 6.6236742434287643e-06}\r\n{x: 0.99966868273464993, z: 2.4381000785678302e-06}\r\n{x: 0.99987807689494357, z: 8.9711476347932211e-07}\r\n{x: 0.99995514181077461, z: 3.3005551447630321e-07}\r\n{x: 0.9999834968924961, z: 1.2142408125806915e-07}\r\n{x: 0.99999392875103243, z: 4.4669889151738637e-08}\r\n{x: 0.99999776649946515, z: 1.6433196923939157e-08}\r\n{x: 0.99999917833933127, z: 6.0454438375448823e-09}\r\n{x: 0.9999996977276967, z: 2.2239956551815462e-09}\r\n{x: 0.99999988880020207, z: 8.1816243629095626e-10}\r\n{x: 0.99999995909187633, z: 3.0098516157414271e-10}\r\n{x: 0.9999999849507416, z: 1.1072625650178e-10}\r\n{x: 0.99999999446368726, z: 4.0733912983436912e-11}\r\n{x: 1.0, z: 1.0, \\fbox{1}: 1.0}\r\n{x: 0.099503719020998152, z: 0.0094544313448217156}\r\n{x: 0.30858339675657204, z: 0.0070641292715984388}\r\n{x: 0.55138385186126571, z: 0.004137253654887871}\r\n{x: 0.7558555212372341, z: 0.0020329156059758929}\r\nSolving took 50 GP solves and 0.828 seconds.\r\n\r\nCost\r\n----\r\n 0.002033\r\n\r\nFree Variables\r\n--------------\r\nx : 0.7559   \r\nz : 0.002033 \r\n\r\n```\r\n\r\nUnsurprisingly, if you set `iteration_limit=22`, the answer is correct:\r\n\r\n```\r\nCost\r\n----\r\n 4.073e-11\r\n\r\nFree Variables\r\n--------------\r\nx : 1         \r\nz : 4.073e-11 \r\n```\r\n\r\ntl;dr the while loop exit condition in `localsolve` doesn't seem to be doing its job.\r\n\r\n\r\n"}}