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

contraction_list: only keep remaining for last 20 contractions #149

Merged
merged 4 commits into from
Jul 19, 2020

Conversation

jcmgray
Copy link
Collaborator

@jcmgray jcmgray commented Jul 16, 2020

Description

Resolves #148, by only keeping the last 10 'remaining terms' lists in the contraction_list, which is generally the point it starts to look a bit messy in the PathInfo object. This could be tweaked / made customizable.

I've also

  • changed the 'speedup' formatting to scientific as this number can be very large sometimes.
  • added a few more spaces inbetween the 'current' contraction and 'remaining terms' for clarity (putting them in [...] might also be clearer.
>>> import opt_einsum as oe
>>> eq, shapes = oe.helpers.rand_equation(20, 3)
>>> path, info = oe.contract_path(eq, *shapes, shapes=True, optimize='greconf')
>>> info
  Complete contraction:  n,aA,jhr,mw,ox,Bos,dc,Cqeu,ipDs,tBk,v,tpkD,u,fram,byqx,znfgd,eCvlbz,icg,jw,yAhl->
         Naive scaling:  30
     Optimized scaling:  6
      Naive FLOP count:  1.680e+21
  Optimized FLOP count:  9.401e+4
   Theoretical speedup:  1.786e+16
  Largest intermediate:  3.888e+3 elements
--------------------------------------------------------------------------------
scaling        BLAS                current                             remaining
--------------------------------------------------------------------------------
   3           GEMM              jw,mw->jm                                   ...
   4           GEMM            jm,jhr->mhr                                   ...
   5           TDOT          mhr,fram->hfa                                   ...
   4           GEMM            hfa,aA->hfA                                   ...
   5    GEMV/EINSUM          znfgd,n->zfgd                                   ...
   4           TDOT            icg,dc->igd                                   ...
   5           GEMM          igd,zfgd->izf                                   ...
   5           TDOT          izf,hfA->izhA                                   ...
   6           TDOT        izhA,yAhl->izyl                                   ...
   5           TDOT          tpkD,tBk->pDB    ox,Bos,Cqeu,ipDs,v,u,byqx,eCvlbz,izyl,pDB->
   5           TDOT          pDB,ipDs->Bis    ox,Bos,Cqeu,v,u,byqx,eCvlbz,izyl,Bis->
   4           TDOT            Bis,Bos->io     ox,Cqeu,v,u,byqx,eCvlbz,izyl,io->
   3           GEMM              io,ox->ix        Cqeu,v,u,byqx,eCvlbz,izyl,ix->
   5           GEMM          ix,byqx->ibyq           Cqeu,v,u,eCvlbz,izyl,ibyq->
   6           TDOT        ibyq,izyl->bqzl                Cqeu,v,u,eCvlbz,bqzl->
   4           GEMM            u,Cqeu->Cqe                   v,eCvlbz,bqzl,Cqe->
   6           TDOT        Cqe,bqzl->Cebzl                      v,eCvlbz,Cebzl->
   6    GEMV/EINSUM        Cebzl,eCvlbz->v                                 v,v->
   1            DOT                  v,v->                                    ->

Status

  • Ready to go

Copy link
Owner

@dgasmith dgasmith left a comment

Choose a reason for hiding this comment

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

You are hitting #147 in the CI as well, for that test can you add a check for (ValueError, TypeError) with a comment like, # changed in Numpy 1.19, see https://github.com/numpy/numpy/commit/35b0a051c19265f5643f6011ee11e31d30c8bc4c?

It's a harmless change.

@@ -51,16 +51,22 @@ def __repr__(self):
" Complete contraction: {}\n".format(self.eq), " Naive scaling: {}\n".format(len(self.indices)),
" Optimized scaling: {}\n".format(max(self.scale_list)), " Naive FLOP count: {:.3e}\n".format(
self.naive_cost), " Optimized FLOP count: {:.3e}\n".format(self.opt_cost),
" Theoretical speedup: {:3.3f}\n".format(self.speedup),
" Theoretical speedup: {:.3e}\n".format(self.speedup),
Copy link
Owner

Choose a reason for hiding this comment

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

+1 the values were getting out of hand.

@@ -303,7 +309,12 @@ def contract_path(*operands, **kwargs):

einsum_str = ",".join(tmp_inputs) + "->" + idx_result

contraction = (contract_inds, idx_removed, einsum_str, input_list[:], do_blas)
if len(input_list) <= 10:
Copy link
Owner

Choose a reason for hiding this comment

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

Any harm in extending this to 15-20?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

None memory wise! 10 was just a rough judgement call on neatness, but 20 feels fine as well.

@codecov
Copy link

codecov bot commented Jul 19, 2020

Codecov Report

Merging #149 into master will decrease coverage by 0.05%.
The diff coverage is 89.47%.

@jcmgray
Copy link
Collaborator Author

jcmgray commented Jul 19, 2020

OK, raised number of 'remaining terms' kept to 20 and should have fixed #147 now as well.

@jcmgray jcmgray changed the title contraction_list: only keep remaining for last 10 contractions contraction_list: only keep remaining for last 20 contractions Jul 19, 2020
Copy link
Owner

@dgasmith dgasmith left a comment

Choose a reason for hiding this comment

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

Looks great!

@dgasmith dgasmith merged commit cb72a33 into dgasmith:master Jul 19, 2020
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.

Remove 'remaining' from PathInfo? (incurs n^2 memory overhead)
2 participants