[petsc-users] Matrix exponential

Paul, Sanku paulsank at msu.edu
Sun Sep 5 19:30:15 CDT 2021


Hi Jose,

    While I am running
from petsc4py import PETSc
>>> print(PETSc.ScalarType)
<class 'numpy.float64'>
only float64 I am getting not complex128.

Do I have to uninstall and then install it? Otherwise doing F.setScale(-1j*t) I am getting an error
File "SLEPc/FN.pyx", line 204, in slepc4py.SLEPc.FN.setScale
  File "SLEPc/SLEPc.pyx", line 115, in slepc4py.SLEPc.asScalar
TypeError: can't convert complex to float

Sanku
________________________________
From: Jose E. Roman <jroman at dsic.upv.es>
Sent: Saturday, September 4, 2021 5:33 AM
To: Paul, Sanku <paulsank at msu.edu>
Cc: PETSc <petsc-users at mcs.anl.gov>
Subject: Re: [petsc-users] Matrix exponential

No problem, do
F.setScale(-1j*t)

What do you mean "still facing problem with complex matrices"? Did you get an error during installation? Did it install for real scalars? Try setting PETSC_CONFIGURE_OPTIONS only, and unset PETSC_DIR PETSC_ARCH. Otherwise pip may not take into account --with-scalar-type=complex

Jose


> El 4 sept 2021, a las 2:11, Paul, Sanku <paulsank at msu.edu> escribió:
>
> Hi Jose,
>
>    I tried to install
> ml -* foss/2019b Python SciPy-bundle/2019.10-Python-3.7.4
> virtualenv slepc4py
> cd slepc4py
> source bin/activate
> pip install numpy mpi4py cython
> export PETSC_CONFIGURE_OPTIONS="--with-scalar-type=complex"
> export PETSC_DIR=/path/to/petsc PETSC_ARCH=your-arch-name
> pip install petsc petsc4py
> pip install slepc slepc4py
>
> But still facing problem with complex matrices. Please help me to fix this.
>
> Thanks,
> Sanku
>
>
> From: Paul, Sanku <paulsank at msu.edu>
> Sent: Friday, September 3, 2021 7:39 PM
> To: Jose E. Roman <jroman at dsic.upv.es>
> Cc: PETSc <petsc-users at mcs.anl.gov>
> Subject: Re: [petsc-users] Matrix exponential
>
> Hi Jose,
>
>    I could now do matrix exponential but facing a problem with a complex matrix. In particular, I want to do \exp(-itH), where H is a Hamiltonian.  How to implement this?
>
> Thanks,
> Sanku
> From: Jose E. Roman <jroman at dsic.upv.es>
> Sent: Friday, September 3, 2021 2:53 PM
> To: Paul, Sanku <paulsank at msu.edu>
> Cc: PETSc <petsc-users at mcs.anl.gov>
> Subject: Re: [petsc-users] Matrix exponential
>
> Please always reply to the list (Reply-All), not to myself.
>
> You should be able to convert from a scipy sparse matrix to a PETSc matrix via PETSc.Mat().createAIJWithArrays(). Don't know how if there is any example in the petsc4py documentation.
>
> Jose
>
>
> > El 3 sept 2021, a las 20:26, Paul, Sanku <paulsank at msu.edu> escribió:
> >
> > Dear Jose,
> >
> >    Thank you very much for your help. I have another question can we just simply pass a sparse.csr.matrix to A. For instance, if B is the sparse.csr.matrix can we do A=B.copy(). Or do I have to do it in a different way?
> >
> > Best,
> > Sanku
> > From: Jose E. Roman <jroman at dsic.upv.es>
> > Sent: Friday, September 3, 2021 2:13 PM
> > To: Paul, Sanku <paulsank at msu.edu>
> > Cc: petsc-users at mcs.anl.gov <petsc-users at mcs.anl.gov>
> > Subject: Re: [petsc-users] Matrix exponential
> >
> > You should either create the FN object and then
> >
> > E.setFN(F)
> >
> > or extract the FN object and assign to a variable
> >
> > F = E.getFN()
> >
> > You can see an example in $SLEPC_DIR/src/binding/slepc4py/demo/ex6.py
> >
> >
> > Jose
> >
> >
> > > El 3 sept 2021, a las 19:53, Paul, Sanku <paulsank at msu.edu> escribió:
> > >
> > > Dear Sir/Ma'am,
> > >
> > >    I am trying to use SLEPc to calculate matrix exponential in my python code but I am not getting the correct result. I have attached the code. Could you let me know what I am doing wrong. This is my first time using SLEPc. So, I would like to ask you if you could send me a tutorial on matrix exponential using SLEPc in python code.
> > >
> > > Best,
> > > Sanku
> > > <ex2.py>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20210906/57b7d404/attachment.html>


More information about the petsc-users mailing list