{"action":"created","issue":{"url":"https://api.github.com/repos/firedrakeproject/firedrake/issues/550","repository_url":"https://api.github.com/repos/firedrakeproject/firedrake","labels_url":"https://api.github.com/repos/firedrakeproject/firedrake/issues/550/labels{/name}","comments_url":"https://api.github.com/repos/firedrakeproject/firedrake/issues/550/comments","events_url":"https://api.github.com/repos/firedrakeproject/firedrake/issues/550/events","html_url":"https://github.com/firedrakeproject/firedrake/issues/550","id":93846753,"number":550,"title":"Rework solver parameter setting","user":{"login":"wence-","id":1126981,"avatar_url":"https://avatars.githubusercontent.com/u/1126981?v=3","gravatar_id":"","url":"https://api.github.com/users/wence-","html_url":"https://github.com/wence-","followers_url":"https://api.github.com/users/wence-/followers","following_url":"https://api.github.com/users/wence-/following{/other_user}","gists_url":"https://api.github.com/users/wence-/gists{/gist_id}","starred_url":"https://api.github.com/users/wence-/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wence-/subscriptions","organizations_url":"https://api.github.com/users/wence-/orgs","repos_url":"https://api.github.com/users/wence-/repos","events_url":"https://api.github.com/users/wence-/events{/privacy}","received_events_url":"https://api.github.com/users/wence-/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/firedrakeproject/firedrake/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-07-08T17:32:39Z","updated_at":"2016-04-14T18:31:54Z","closed_at":null,"body":"Right now, we generate a unique prefix for every solver and allow a user to specify an options_prefix by hand.  The petsc default is to have the same (NULL) prefix for everything unless set.  Due to how we then set options for solvers, things get messy really fast.  Furthermore, to kill various things from the petsc options database, we have custom __del__ methods that occasionally result in unfriendly error messages."},"comment":{"url":"https://api.github.com/repos/firedrakeproject/firedrake/issues/comments/210090571","html_url":"https://github.com/firedrakeproject/firedrake/issues/550#issuecomment-210090571","issue_url":"https://api.github.com/repos/firedrakeproject/firedrake/issues/550","id":210090571,"user":{"login":"stephankramer","id":3791078,"avatar_url":"https://avatars.githubusercontent.com/u/3791078?v=3","gravatar_id":"","url":"https://api.github.com/users/stephankramer","html_url":"https://github.com/stephankramer","followers_url":"https://api.github.com/users/stephankramer/followers","following_url":"https://api.github.com/users/stephankramer/following{/other_user}","gists_url":"https://api.github.com/users/stephankramer/gists{/gist_id}","starred_url":"https://api.github.com/users/stephankramer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stephankramer/subscriptions","organizations_url":"https://api.github.com/users/stephankramer/orgs","repos_url":"https://api.github.com/users/stephankramer/repos","events_url":"https://api.github.com/users/stephankramer/events{/privacy}","received_events_url":"https://api.github.com/users/stephankramer/received_events","type":"User","site_admin":false},"created_at":"2016-04-14T18:31:54Z","updated_at":"2016-04-14T18:31:54Z","body":"Can I flag this up again? My main bugbear is that when you use the same options_prefix twice, your solver options for the second solve may be totally ignored if they were already set in the first solve:\r\n\r\n    from firedrake import *    \r\n    mesh=UnitSquareMesh(10,10)    \r\n    V = FunctionSpace(mesh, \"CG\", 1)\r\n    v = TestFunction(V)\r\n    u = Function(V)    \r\n    F = v*u*dx-v*Constant(1.0)*dx==0\r\n\r\n    solve(F, u, solver_parameters={'ksp_type': 'preonly', 'pc_type': 'lu'}, options_prefix='foo_')\r\n    # should fail with unknown pc_type, but gets ignored:\r\n    solve(F, u, solver_parameters={'ksp_type': 'preonly', 'pc_type': 'bork'}, options_prefix='foo_')\r\n\r\nThe reason for this is that in the first call the prefixed options ('foo_ksp_type', etc.) are inserted in the global PETSc.Options dictionary and never removed again. In the second solve, it then overrides the provided solver_parameters with those already present in PETSc.Options (on the erronous assumption that they were command-line arguments).\r\n\r\nOne could argue of course that people shouldn't be using the same prefix for two different solves, but just as an example where this goes wrong: in Thetis we prefix the solves with the name of the time integrator. Now if I setup a problem in two separate tests that happen to use the same time integration scheme, and I run them in the same py.test session (as on Travis) the second test still picks up solver options from the first test (and those of the first test always win).\r\n\r\nNot entirely sure how to fix this properly. In particular, if you also want to support two solvers with the same options_prefix to exist concurrently it is very unclear when which options should be set in PETSc.Options(). If you at least assume the first solver is deleted before the second one, you could try to fix PETSc.Options() - but you'd have to be careful not to overwrite options that were actually set on the command line. A completely different approach would be to always use an auto_prefix and only use the provided options_prefix to pull command-line options from PETSc.Options() and stick these back in with options_prefix replaced by the auto_prefix.\r\n"}}