Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: move nullspace to mat #47

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from
Draft

Conversation

haplav
Copy link
Collaborator

@haplav haplav commented May 28, 2020

No description provided.

@haplav
Copy link
Collaborator Author

haplav commented May 29, 2020

@jkruzik May I ask you for a preliminary review? I will finish things like writing manpages and finishing some of the TODOs once the concept is agreed.

@haplav haplav requested a review from jkruzik May 29, 2020 10:39
src/mat/impls/inv/matinv.c Outdated Show resolved Hide resolved
src/mat/impls/inv/matinv.c Show resolved Hide resolved
src/mat/impls/inv/matinv.c Outdated Show resolved Hide resolved
src/mat/impls/inv/matinv.c Outdated Show resolved Hide resolved
src/mat/impls/inv/matinv.c Outdated Show resolved Hide resolved
src/mat/impls/inv/matinv.c Outdated Show resolved Hide resolved
src/qp/interface/qptransform.c Outdated Show resolved Hide resolved
@haplav haplav force-pushed the haplav/move-nullspace-to-mat branch from 87913bf to 2f6ab7a Compare May 29, 2020 13:18
src/mat/impls/inv/matinv.c Outdated Show resolved Hide resolved
src/mat/impls/inv/matinv.c Outdated Show resolved Hide resolved
@haplav haplav force-pushed the haplav/move-nullspace-to-mat branch from 4286796 to 112b61d Compare May 29, 2020 15:24
@haplav

This comment has been minimized.

@haplav haplav force-pushed the haplav/move-nullspace-to-mat branch from 09c7296 to 738ff88 Compare June 9, 2020 14:19
@haplav
Copy link
Collaborator Author

haplav commented Jun 17, 2020

#47 (comment)

Note that, I still think there should be MatCheckNullSpaceMat in dbg mode in Compute function.

OK, done now in fb2f271.

Note also MatCheckNullSpaceMat now returns flag instead of failing. That gives more flexibility how it can be used.

@haplav haplav force-pushed the haplav/move-nullspace-to-mat branch from fb2f271 to 357f4f8 Compare June 17, 2020 14:45
@haplav
Copy link
Collaborator Author

haplav commented Jun 17, 2020

(partial squash)

@haplav
Copy link
Collaborator Author

haplav commented Jun 18, 2020

TODO

  • Move nullspace computation from matinv.c to permonmatnullspace.c
  • Add manpages to functions in permonmatnullspace.c
  • Do some more squashing.

TRY( MatInvSetNullSpace(Kplus,R) );
} else {
TRY( MatGetNullSpaceMat(K,&R) );
if (!R) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can lead to a wrong result, if K changes after a call to MatSetNullSpaceMat(). We need to ensure that R is a valid nullspace as I was saying throughout #47 (comment). My suggestion is to store K ObjState on Set().

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree this is an issue (quite hypothetical at the moment, though).

However, as you can see in diff, view, this issue is not introduced by this PR. It was there before, and it's not a goal of this PR to solve it. It's more convenient for me to fix everything about nullspace use in QPTDualize in #20 and fits its scope better. And there will probably be another discussion how exactly all this will be implemented.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mentioned now in TODOs #20 (comment)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though, the bug is introduced by this PR. We had QPSetNullSpaceOperator() and therefore users knew that QP object uses R - changing K after setting R to QP is a bug in user code. Now, R is hidden in K and users have no idea that QP uses R.

Almost all of the comments from my point of view in #47 (comment) were about solving this bug regardless of superficial naming and benchmarking stuff. It should be solved here as it is not related to the singular Hessian in QPTDualize.

As was pointed out many times, there is an easy solution with ObjState tracking.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though, the bug is introduced by this PR.

This is funny. First of all, the "bug" is not even covered by tests. So it's rather hypothetical. Feel free to add a few tests in #20 which will make this bug reproducible and I will have to fix it in order to make tests passing.

We had QPSetNullSpaceOperator() and therefore users knew that QP object uses R - changing K after setting R to QP is a bug in user code. Now, R is hidden in K and users have no idea that QP uses R.

If the user has no idea, then she/he probably doesn't set the nullspace at all and then it gets computed automatically in QPTDualize with correct results. No change here.

If additionally they change K after QPTDualize and then call QPTDualize again, they get wrong results. No change here. [Quite unlikely use case as of now, though.]

It the user explicitly sets/computes nullspace, it is intentional act on their side and they take the responsibility. No change here.

And if they change the operator afterwards, then they get wrong results. No change here.

There was never before a mechanism to really protect from these issues. Stating that it had been a user code bug and now it is our bug, just because R is now directly a K property, is ridiculous. And it's the more so fishy argumentation that it has never been properly explained in docs so it's always our fault actually.

However, there could have been problems with syncing R in MATINV and R in QP before, which are now gone at least.

As was pointed out many times, there is an easy solution with ObjState tracking.

I don't question it. But it's not the only solution. I asked you to postpone the discussion to #20 and you once again make me to add some reasons for it, which is quite frustrating, but OK.

We could as well make really sure the provided nullspace is correct by calling CheckNullSpaceMat in QPTDualize - its cost is a few purely local matrix-vector products and maybe it would pay off to do that rather than rely on ObjState or so. I don't advocate that right now and I don't wanna discuss it here. I need to think about that. And it's a matter of #20 which will follow.

Could you please let me do things in my preferred order since I'm the one who will implement it eventually? I promised I would solve it in #20. I thought that should normally suffice. So if you let me do my job, I will finish the TODOs and it will be ready for merge.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I probably did not make myself clear, what I want to know is why do you believe it is better to fix it in #20 and not here. My reasoning is that it clearly falls into the scope of this PR while it has nearly nothing to do with non-singular Hessian in QPTDualize. The other thing is that merging something with a known fault with a view of hopefully fixing it down the line is a bad idea. To reiterate, it is possible to solve it in #20 if there is a good reason to do it there and it falls into its scope (I really struggle to see the latter point).

Another solution, which would suffice and is the simplest, is to leave this as is, but then it should be mentioned in the doc to QP object and QPTDualize that it uses R attached using MatSetNullSpaceMat() to the operator set by QPSetOperator().

At first, I wanted to end my reply here and skip replying to most of the things you raised because it is actually not related to what I need to know from you. Clearly, whether this problem stems from the changes in this PR (which has nothing to do with a simple diff but rather the composition of the objects) can be contested, but ultimately the problem is here, it was found due to this PR and is clearly related to it. However, I do feel obligated to clear some of the points and comment on some of your reasoning that I considered flawed.

This is funny. First of all, the "bug" is not even covered by tests. So it's rather hypothetical.

Saying that a problem is not covered by a test is irrelevant - it is still a problem

Feel free to add a few tests in #20 which will make this bug reproducible and I will have to fix it in order to make tests passing.

I am not going to put code directly into your PR unless you specifically ask me to do so. However, if I were to do that I could choose to add the aforementioned test into this PR.

We had QPSetNullSpaceOperator() and therefore users knew that QP object uses R - changing K after setting R to QP is a bug in user code. Now, R is hidden in K and users have no idea that QP uses R.

If the user has no idea, then she/he probably doesn't set the nullspace at all and then it gets computed automatically in QPTDualize with correct results. No change here.

I said that, with these changes, the user does not know that setting null space into K affects operations on QP object. There is a fundamental difference between
QPSetOperatorNullSpace(QP,Mat)
which operates on QP objects and
MatSetNullSpaceMat(Mat,Mat),
because in the latter there is no obvious connection to QP. That should certainly be mentioned in the doc.

If additionally they change K after QPTDualize and then call QPTDualize again, they get wrong results. No change here. [Quite unlikely use case as of now, though.]

I never mentioned this anywhere.

It the user explicitly sets/computes nullspace, it is intentional act on their side and they take the responsibility. No change here.

There was never before a mechanism to really protect from these issues. Stating that it had been a user code bug and now it is our bug, just because R is now directly a K property, is ridiculous. And it's the more so fishy argumentation that it has never been properly explained in docs so it's always our fault actually.

Again the difference is that with setting the nullspace to Mat there is no obvious connection to QP.

However, there could have been problems with syncing R in MATINV and R in QP before, which are now gone at least.

Yes, that is good although besides the point.

As was pointed out many times, there is an easy solution with ObjState tracking.

I don't question it. But it's not the only solution. I asked you to postpone the discussion to #20 and you once again make me to add some reasons for it, which is quite frustrating, but OK.

Yes, I did want some good reasons to postpone this to #20, and as a reply, I did get a very long message that does not give any reason to postpone it. You just argued why this problem is similar to the state before the change.

I promised I would solve it in #20. I thought that should normally suffice.

No. What suffices is a clear reason why it should be done in #20.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

2 participants