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

Refactor quadratic form #64

Open
wants to merge 1 commit into
base: mk/quadratic_form
Choose a base branch
from
Open

Refactor quadratic form #64

wants to merge 1 commit into from

Conversation

blegat
Copy link
Member

@blegat blegat commented Jan 28, 2025

No description provided.

if basis(A) isa DiracBasis
return c == cfs1
else
dc = coeffs(c, basis(a), DiracBasis(object(parent(a))))
Copy link
Member Author

Choose a reason for hiding this comment

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

@kalmarek You need to explain me what this was all about

Copy link
Collaborator

Choose a reason for hiding this comment

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

it's a stopgap solution on how to construct SparseCoefficients for a unit in arbitrary basis.
Here what I try to do is to create the unit in the DiracBasis which does contain unit as a vector and then rewrite it to the basis of a.

improvements are welcome!

However I think what you suggested is wrong:

    if !isone(length(nonzero_pairs(c)))
        return false
    end
    key, coef = only(nonzero_pairs(c))
    return isone(coef) && isone(basis(a)[key])

The suggestion is correct only when unit is an element of a basis. If our basis contains vectors (1+x, 1-x) (add 1/√2 factor to make it orthogonal) then the unit will be written with the corresponding coefficients (1/2, 1/2) (add √2 if you like).

MA.operate!(
UnsafeAdd(),
res,
SparseCoefficients((_key(op.structure, k),), (cfs,)),
Copy link
Member Author

@blegat blegat Jan 28, 2025

Choose a reason for hiding this comment

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

This _key things seems hacky, can't you apply _key in the structure function just before returning ? So that this complexity does not leave the multiplicative struct ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

well, according to git blame You added this _key thing to work around the MTable quirkiness ;)
But anyway, maybe I need to rethink MTable as well (or disable it completely for now, until we get the things working?)

if basis(A) isa DiracBasis
return c == cfs1
else
dc = coeffs(c, basis(a), DiracBasis(object(parent(a))))
Copy link
Collaborator

Choose a reason for hiding this comment

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

it's a stopgap solution on how to construct SparseCoefficients for a unit in arbitrary basis.
Here what I try to do is to create the unit in the DiracBasis which does contain unit as a vector and then rewrite it to the basis of a.

improvements are welcome!

However I think what you suggested is wrong:

    if !isone(length(nonzero_pairs(c)))
        return false
    end
    key, coef = only(nonzero_pairs(c))
    return isone(coef) && isone(basis(a)[key])

The suggestion is correct only when unit is an element of a basis. If our basis contains vectors (1+x, 1-x) (add 1/√2 factor to make it orthogonal) then the unit will be written with the corresponding coefficients (1/2, 1/2) (add √2 if you like).

MA.operate!(
UnsafeAdd(),
res,
SparseCoefficients((_key(op.structure, k),), (cfs,)),
Copy link
Collaborator

Choose a reason for hiding this comment

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

well, according to git blame You added this _key thing to work around the MTable quirkiness ;)
But anyway, maybe I need to rethink MTable as well (or disable it completely for now, until we get the things working?)

Comment on lines +82 to +85
function MA.operate!(op::UnsafeAddMul, res, A, B, α)
for (kA, vA) in nonzero_pairs(A)
for (kB, vB) in nonzero_pairs(B)
cfs = MA.@rewrite α * vA * vB
MA.operate!(op, res, op.structure(kA, kB), C, cfs)
MA.operate!(op, res, op.structure(kA, kB), α * vA * vB)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I understand that you just removed the ABCα variant of UnsafeAddMul? Can you also remove the failing tests (as we don't plan to support this feature)?

@blegat
Copy link
Member Author

blegat commented Jan 31, 2025

Note that I think this PR made SymbolicWedderburn fail 😢

@kalmarek
Copy link
Collaborator

yes, since it relies on MTables

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

Successfully merging this pull request may close these issues.

2 participants