# plotplease = False

(My, A, rhs, nfunc, femp) = dbs.\
    burgers_spacedisc(N=Nq, nu=nu, retfemdict=True)

iniv = np.r_[np.ones(((Nq - 1) / 2, 1)), np.zeros(((Nq) / 2, 1))]


def fwdrhs(t):
    return rhs


simudict = dict(iniv=iniv, A=A, M=My, nfunc=nfunc, rhs=fwdrhs, tmesh=tmesh)
vv = gpu.time_int_semil(**simudict)
if plotplease:
    plotmat(vv, fignum=1234)

(xms, Ms) = gpu.get_genmeasuremat(sol=vv.T, tmesh=tmesh, sdim=Ns)

from ext_cholmod import SparseFactorMassmat
myfac = SparseFactorMassmat(sps.csc_matrix(My))
msfac = SparseFactorMassmat(sps.csc_matrix(Ms))
# My = myfac.F*myfac.Ft
# Ms = msfac.F*msfac.Ft

lytxms = myfac.Ft * xms
lytxlst = (msfac.solve_Ft(lytxms.T)).T
xlst = (msfac.solve_Ft(xms.T)).T

Uky, _ = gpu.get_podbases(measmat=lytxlst, nlsvecs=hq, nrsvecs=0)
예제 #2
0
        format(norm(bnonlvalk-btensvalk)/norm(testvk))
    print 'rel projection error in the nonl. evaluation: {0}'.\
        format(norm(bnonlval-np.dot(Uky, btensvalk))/norm(testvk))
    print 'rel projection error in the state: {0}'.\
        format(norm(testv-np.dot(Uky, testvk))/norm(testv))

# check the linear space time residual
plotplease = False

linsimudict = dict(iniv=iniv, A=A, M=My, nfunc=None,
                   rhs=rhs, tmesh=tmesh)
vvl = dou.\
    load_or_comp(filestr='data/lincase_'+datastr, comprtn=gpu.time_int_semil,
                 comprtnargs=linsimudict, arraytype='dense', debug=True)
if plotplease:
    plotmat(vvl, fignum=125)

(msxlin, Ms) = gpu.get_genmeasuremat(sol=vvl.T, tmesh=tmesh, sdim=Ns)
xlin = lau.apply_massinv(sps.csc_matrix(Ms), msxlin.T).T

if not redmodel:
    Ukylin, Ukslin = np.eye(Nq-1), np.eye(Ns)
    hs, hq = Ns, Nq-1
    Ms = gpu.get_ms(sdim=Ns, tmesh=tmesh, basfuntype='pl')
    dms = gpu.get_dms(sdim=Ns, tmesh=tmesh, basfuntype=timebasfuntype)
    rbd = dict(hmy=My.todense(), hay=A.todense(), hms=Ms, hdms=dms,
               inivred=iniv, hrhs=rhs, hnonl=nfunc)

else:
    Ukylin, Ukslin = gpu.get_timspapar_podbas(hs=hs, hq=hq, plotsvs=plotplease,
                                              My=My, Ms=Ms, snapsl=[xlin])
        sol = np.linalg.solve(solmat, rhs)

    fsol = np.hstack([iniv, sol.reshape((lns - 1, lnq)).T])
    return fsol


fullsyslincheck = True
fopti = False
if fullsyslincheck:
    fsol = sollintimspasys(dms=dms,
                           ms=ms,
                           ay=np.array(ay.todense()),
                           my=np.array(my.todense()),
                           iniv=iniv,
                           opti=fopti)
    plotmat(fsol.T, fignum=122)
smasyslincheck = True
sopti = True
if smasyslincheck:
    ssol = sollintimspasys(dms=hdms,
                           ms=hms,
                           ay=ared,
                           my=mred,
                           iniv=inivred,
                           opti=sopti)
    fssolt = np.dot(np.dot(Uks, ssol.T), Uky.T)
    plotmat(fssolt, fignum=124)

plotmat(fssolt - fsol.T, fignum=133)
# plotmat(fssolt - x.T, fignum=144)
예제 #4
0
    burgers_spacedisc(N=Nq, nu=nu, retfemdict=True)
# +1 bc of boundary conditions that are eliminated
femp, ay, my = femp, A, M
tmesh = np.linspace(t0, tE, Nts)
iniv = np.r_[np.zeros((np.floor(Nq * .5), 1)),
             np.ones((np.ceil(Nq * .5) - 1, 1))]
# iniv = np.ones((Nq-1, 1))
datastr = 'burgv_contim_nu{1}_N{0}_Nts{2}'.format(Nq, nu, Nts)

simudict = dict(iniv=iniv, A=A, M=M, nfunc=None, rhs=rhs, tmesh=tmesh)
vv = dou.load_or_comp(filestr='data/' + datastr,
                      comprtn=gpu.time_int_semil,
                      comprtnargs=simudict,
                      arraytype='dense',
                      debug=True)
plotmat(vv)
ared, mred, nonlred, rhsred, inired, Uky = gpu.\
    get_podred_model(M=M, A=A, nonl=nfunc, rhs=rhs,
                     sol=vv.T, tmesh=tmesh, verbose=True,
                     poddim=hq, sdim=Ns, plotsvs=plotsvs,
                     genpod=True, basfuntype='pl')

(msx, ms) = gpu.get_genmeasuremat(sol=vv.T, tmesh=tmesh, sdim=Ns)
x = lau.apply_massinv(sps.csc_matrix(ms), msx.T).T
Uks = gpu.get_podmats(sol=x.T, poddim=hs, plotsvs=plotsvs, M=M)
hshysol = np.dot(Uks.T, np.dot(x.T, Uky)).\
    reshape((hs*hq, 1), order='C')
dms = gpu.get_dms(sdim=Ns, tmesh=tmesh, basfuntype='pl')
hdms = np.dot(Uks.T, np.dot(dms, Uks))
hms = np.dot(Uks.T, np.dot(ms, Uks))
nres, timespaceres = get_spacetimepodres(tvvec=hshysol,
예제 #5
0
def bfgs_opti(Nq=None,
              Nts=None,
              inivtype=None,
              dmndct=None,
              Ns=None,
              hq=None,
              hs=None,
              redrtol=None,
              redatol=None,
              spacebasscheme=None,
              nu=None,
              alpha=None,
              podstate=False,
              podadj=False,
              genpodcl=False,
              plotplease=None,
              tikzplease=False,
              tikzprefikz='',
              adjplotdict=None,
              bfgsiters=None,
              gtol=1e-5,
              target='inival',
              checkbwdtimings=False,
              onlytimings=False,
              **kwargs):

    dmndct.update(dict(plotplease=plotplease))

    t0, tE = dmndct['t0'], dmndct['tE']

    tmesh = np.linspace(t0, tE, Nts)
    # snapshottmesh = np.linspace(t0, tE, Ns)
    redtmesh = np.linspace(t0, tE, hs)
    # ### define the model

    if target == 'inival':

        def vstar(t):
            return iniv.flatten()

    elif target == 'heart' or 'invheart':
        invertt = True if target == 'invheart' else False
        myheartfun = get_spcheartfun(NY=Nq - 1, invertt=invertt)

        def vstar(t):
            return myheartfun(t).flatten()

    x0, xE = dmndct['x0'], dmndct['xE']

    (My, A, rhs, nfunc, femp) = dbs.\
        burgers_spacedisc(N=Nq, nu=nu, x0=x0, xE=xE, retfemdict=True)
    iniv = dbs.burger_onedim_inival(Nq=Nq, inivtype=inivtype)

    # ### compute the forward snapshots
    def fwdrhs(t):
        return rhs

    simudict = dict(iniv=iniv, A=A, M=My, nfunc=nfunc, rhs=fwdrhs, tmesh=tmesh)
    with dou.Timer('fwd'):
        datastr = 'data/fwdsol_iniv' + inivtype + '_target' + target +\
            'Nq{0}Nts{1}nu{2}'.format(Nq, Nts, nu)
        # vv = gpu.time_int_semil(**simudict)
        vv = dou.load_or_comp(filestr=datastr,
                              comprtn=gpu.time_int_semil,
                              arraytype='dense',
                              comprtnargs=simudict,
                              debug=debug)
    plotmat(vv, fignum=1234, **dmndct)

    (xms, Ms) = gpu.get_genmeasuremat(sol=vv.T, tmesh=tmesh, sdim=Ns)
    # ### compute the backward snapshots
    vfun = interp1d(tmesh, vv, axis=0, fill_value='extrapolate')
    vdxoperator, fnctnl = dbs.\
        burgers_bwd_spacedisc(V=femp['V'], ininds=femp['ininds'],
                              diribc=femp['diribc'])
    te = tmesh[-1]

    def burger_bwd_rhs(t):
        # TODO: -----------------------------> here we need vstar
        return -fnctnl(vfun(te - t)).flatten() + fnctnl(
            vstar(te - t)).flatten()

    def burger_bwd_nonl(lvec, t):
        vdx = vdxoperator(vfun(te - t))
        return -(vdx * lvec).flatten()

    termiL = np.zeros((Nq - 1, 1))
    bbwdsimudict = dict(iniv=termiL,
                        A=A,
                        M=My,
                        nfunc=burger_bwd_nonl,
                        rhs=burger_bwd_rhs,
                        tmesh=tmesh)

    with dou.Timer('bwd'):
        datastr = 'data/bwdsol_iniv' + inivtype + '_target' + target + \
            'Nq{0}Nts{1}nu{2}'.format(Nq, Nts, nu)
        bwdll = dou.\
            load_or_comp(filestr=datastr, comprtn=gpu.time_int_semil,
                         arraytype='dense', comprtnargs=bbwdsimudict,
                         debug=debug)
        # bwdll = gpu.time_int_semil(**bbwdsimudict)
    ll = np.flipud(bwdll)  # flip the to make it forward time
    if adjplotdict is None:
        adjplotdict = dmndct
    plotmat(ll, fignum=1235, **adjplotdict)

    (Lms, _) = gpu.get_genmeasuremat(sol=ll.T, tmesh=tmesh, sdim=Ns)

    # ### compute the projection matrices, i.e. optimal bases
    (lyitUVy, lyUVy, lsitUVs, lsUVs, lyitULy, lyULy, lsitULs, lsULs) = gou.\
        stateadjspatibas(xms=xms, lms=Lms, Ms=Ms, My=My, nspacevecs=hq,
                         ntimevecs=hs, spacebasscheme=spacebasscheme)
    # ## the fwd projection scheme
    AVk, MVk, nonl_red, rhs_red, liftVcoef, projVcoef =\
        gpu.get_spaprjredmod(M=My, A=A, nonl=nfunc, rhs=fwdrhs,
                             Uk=lyitUVy, prjUk=lyUVy)
    hiniv = projVcoef(iniv)
    # ## preassemble reduced nonlinearity as tensor
    print 'assembling the reduced tensor...'
    import burgers_genpod_utils as bgu
    datastr = 'data/fwd_iniv' + inivtype + '_tnsr_' + spacebasscheme + \
        '_target_' + target +\
        '_Nts{4}Nq{0}Ns{1}hq{2}nu{3}'.format(Nq, Ns, hq, nu, Nts)
    uvvdxl, _ = bgu.\
        get_burger_tensor(Uky=lyitUVy, Uks=lsitUVs, bwd=True, spaceonly=True,
                          # Vhdms=None, Vhms=None, Vhmy=MVk, Vhay=AVk,
                          # sdim=Ns, tmesh=tmesh,
                          datastr=datastr, debug=debug, **femp)

    def redfwdnln_tns(vvec, t):
        return bgu.eva_burger_spacecomp(uvvdxl=uvvdxl, svec=vvec).flatten()

    # ## the bwd projection scheme
    ALk, MLk, _, _, liftLcoef, projLcoef =\
        gpu.get_spaprjredmod(M=My, A=A, nonl=burger_bwd_nonl,
                             rhs=burger_bwd_rhs, Uk=lyitULy, prjUk=lyULy)
    htermiL = projLcoef(termiL)

    red_vdxop = gpu.get_redmatfunc(matfunc=vdxoperator,
                                   ULk=lyitULy,
                                   UVk=lyitUVy)

    print 'assembling the bwd reduced tensor...'
    datastr = 'data/bwdtnsr_iniv' + inivtype + '_' + spacebasscheme +\
        '_target_' + target +\
        '_Nts{4}Nq{0}Ns{1}hq{2}nu{3}'.format(Nq, Ns, hq, nu, Nts)
    Luvvdxl, _ = bgu.\
        get_burger_tensor(Uky=lyitULy, bwd=True, spaceonly=True,
                          Ukyconv=lyitUVy,
                          datastr=datastr, debug=debug,
                          **femp)

    # ## the mixed matrices
    VLhmy = np.dot(lyitUVy.T, My * lyitULy)
    LVhmy = np.dot(lyitULy.T, My * lyitUVy)

    redvstarvec = gou.functovec(vstar, redtmesh, projcoef=projVcoef)
    vstarvec = gou.functovec(vstar, tmesh)

    eva_redfwd = gou.get_eva_fwd(
        iniv=hiniv,
        MV=MVk,
        AV=AVk,
        MVU=VLhmy,
        rhs=rhs_red,
        nonlfunc=redfwdnln_tns,
        # nonlfunc=nonl_red,
        solvrtol=redrtol,
        solvatol=redatol,
        tmesh=redtmesh)

    eva_redbwd = gou.get_eva_bwd(vstarvec=redvstarvec,
                                 MLV=LVhmy,
                                 ML=MLk,
                                 AL=ALk,
                                 termiL=htermiL,
                                 tmesh=redtmesh,
                                 bwdvltens=Luvvdxl,
                                 solvrtol=redrtol,
                                 solvatol=redatol,
                                 vdxoperator=red_vdxop)
    if checkbwdtimings:
        rdvvec = eva_redfwd(np.zeros((hq, hs)))
        return eva_redbwd, rdvvec

    eva_liftufwd = gou.get_eva_fwd(iniv=iniv,
                                   MV=My,
                                   AV=A,
                                   MVU=My,
                                   rhs=fwdrhs,
                                   nonlfunc=nfunc,
                                   tmesh=tmesh,
                                   redtmesh=redtmesh,
                                   liftUcoef=liftLcoef)

    eva_redcostfun, eva_redcostgrad = \
        gou.get_eva_costfun(tmesh=redtmesh, MVs=MVk, MUs=alpha*MLk,
                            vstarvec=redvstarvec, getcompgrad=True,
                            eva_fwd=eva_redfwd, eva_bwd=eva_redbwd)

    eva_liftucostfun = \
        gou.get_eva_costfun(tmesh=tmesh, MVs=My,
                            utmesh=redtmesh, MUs=alpha*MLk,
                            vstarvec=vstarvec, eva_fwd=eva_liftufwd)

    checktest = True
    checktest = False
    if checktest:
        dmndct.update(dict(plotplease=True))
        rdvvec = eva_redfwd(np.zeros((hq, hs)))
        rdvv = gou.xvectoX(rdvvec, nq=hq, ns=hs)
        plotmat(np.dot(lyitUVy, rdvv).T, fignum=2135, **dmndct)

        rdlvec = eva_redbwd(rdvvec)
        rdll = gou.xvectoX(rdlvec, nq=hq, ns=hs)
        plotmat(np.dot(lyitULy, rdll).T, fignum=2136, **dmndct)

        plotmat(np.dot(lyitUVy, gou.xvectoX(redvstarvec, ns=hs, nq=hq)).T,
                fignum=324,
                **dmndct)
        checktestjaco = True
        checktestjaco = False
        if checktestjaco:
            import numdifftools as nd
            uk = gou.Xtoxvec(np.zeros((hq, hs)))
            myjaco = eva_redcostgrad(gou.Xtoxvec(uk).flatten())
            ndjaco = nd.Jacobian(eva_redcostfun)(gou.Xtoxvec(uk).flatten())
            print 'diffnorm of the analytical and the numerical jacobian' +\
                  ' `dJ={0}`'.format(np.linalg.norm(myjaco-ndjaco))

    uk = gou.Xtoxvec(np.zeros((hq, hs)))

    tfd = {}  # if timerecord else None
    print 'solving the reduced optimization problem'

    profileit = False
    if profileit:
        from pycallgraph import PyCallGraph
        from pycallgraph.output import GraphvizOutput
        with PyCallGraph(output=GraphvizOutput()):
            uopt, fopt, gopt, Bopt, nfc, ngc, wflag = \
                fmin_bfgs(eva_redcostfun, gou.Xtoxvec(uk), full_output=True,
                          fprime=eva_redcostgrad, maxiter=bfgsiters, gtol=gtol)
    with dou.Timer('bfgs optimization', timerinfo=tfd):
        uopt, fopt, gopt, Bopt, nfc, ngc, wflag = \
            fmin_bfgs(eva_redcostfun, gou.Xtoxvec(uk), full_output=True,
                      fprime=eva_redcostgrad, maxiter=bfgsiters, gtol=gtol)
        tfd.update(dict(nfc=nfc, ngc=ngc))

    if onlytimings:
        minfcallgcall = min(nfc, ngc)  # minimum of func/grad calls
        tfwdclt = []
        tfwdclo = []
        dumfwd = 0 * uk
        for k in range(3):
            ltfd = {}
            with dou.Timer('', verbose=False, timerinfo=ltfd):
                dumfwd = eva_redfwd(uopt)
            tfwdclo.append(ltfd['elt'])
            ltfd = {}
            with dou.Timer('', verbose=False, timerinfo=ltfd):
                dumfwd = eva_redfwd(gou.Xtoxvec(uk))
            tfwdclt.append(ltfd['elt'])
        dumfwd = 0 * dumfwd
        medfwdcall = 0.5 * (np.median(np.array(tfwdclo)) +
                            np.median(np.array(tfwdclt)))
        funccalloverhead = minfcallgcall * medfwdcall
        tfd.update(dict(overhead=funccalloverhead))

        return tfd

    else:
        print 'evaluating the full cost function'
        fulcostvpart, fulcostupart = eva_liftucostfun(uopt, retparts=True)

        if plotplease:
            vvecopt = eva_liftufwd(uopt)
            vopt = gou.xvectoX(vvecopt, nq=Nq - 1, ns=Nts)
            plotmat(vopt.T, fignum=3234, **dmndct)

        return dict(vterm=fulcostvpart,
                    uterm=fulcostupart,
                    value=fulcostupart + fulcostvpart,
                    unormsqrd=2 * 1. / alpha * fulcostupart), tfd
예제 #6
0
simudict = dict(iniv=iniv,
                A=A,
                M=My,
                nfunc=nfunc,
                rhs=fwdrhs,
                tmesh=snapshottmesh)

print 'back check...'

vv, infodict = gpu.time_int_semil(full_output=True, **simudict)
print infodict['nst'][-1]
raise Warning('TODO: debug')

vopt = np.tile(iniv.T, (Ns, 1))
if plotplease:
    plotmat(vv, fignum=12341, **dmndct)
    vvd = vv - np.tile(iniv.T, (Ns, 1))

    plotmat(vvd, fignum=12342, **dmndct)

    plotmat(vopt, fignum=12343, **dmndct)


def vstar(t):
    return qvstar * iniv.T


valdict = eva_costfun(vopt=Xtoxvec(qalpha * vv.T),
                      uopt=Xtoxvec(uopt),
                      qmat=qalpha * My,
                      rmat=alpha * My,
import dolfin_burgers_scipy as dbs
import gen_pod_utils as gpu
import numpy as np
from plot_utils import plotmat

Nq = 100  # dimension of the spatial discretization
Nts = 100  # number of time sampling points
t0, tE = 0., 1.
tmesh = np.linspace(t0, tE, Nts)
nu = 1e-3
(My, A, rhs, nfunc, femp) = dbs.\
    burgers_spacedisc(N=Nq, nu=nu, retfemdict=True)

iniv = np.r_[np.ones(((Nq - 1) / 2, 1)), np.zeros(((Nq) / 2, 1))]
simudict = dict(iniv=iniv, A=A, M=My, nfunc=nfunc, rhs=rhs, tmesh=tmesh)
vv = gpu.time_int_semil(**simudict)
plotmat(vv, fignum=1234)
예제 #8
0
def space_genpod_burger(Nq=None,
                        Nts=None,
                        inivtype=None,
                        dmndct=None,
                        Ns=None,
                        hq=None,
                        hs=None,
                        spacebasscheme=None,
                        nu=None,
                        alpha=None,
                        plotplease=False,
                        tikzprefikz='',
                        adjplotdict=None,
                        onlytimings=False,
                        **kwargs):

    t0, tE = dmndct['t0'], dmndct['tE']

    tmesh = np.linspace(t0, tE, Nts)
    # snapshottmesh = np.linspace(t0, tE, Ns)
    redtmesh = np.linspace(t0, tE, hs)
    # ### define the model
    x0, xE = dmndct['x0'], dmndct['xE']

    (My, A, rhs, nfunc, femp) = dbs.\
        burgers_spacedisc(N=Nq, nu=nu, x0=x0, xE=xE, retfemdict=True)
    iniv = dbs.burger_onedim_inival(Nq=Nq, inivtype=inivtype)

    # ### compute the forward snapshots
    def fwdrhs(t):
        return rhs

    simudict = dict(iniv=iniv, A=A, M=My, nfunc=nfunc, rhs=fwdrhs, tmesh=tmesh)
    with dou.Timer('fwd'):
        datastr = 'data/fwdsol_iniv' + inivtype + \
            'Nq{0}Nts{1}nu{2}'.format(Nq, Nts, nu)
        # vv = gpu.time_int_semil(**simudict)
        vv = dou.load_or_comp(filestr=datastr,
                              comprtn=gpu.time_int_semil,
                              arraytype='dense',
                              comprtnargs=simudict,
                              debug=debug)
    plotmat(vv, fignum=1236, **dmndct)

    (xms, Ms) = gpu.get_genmeasuremat(sol=vv.T, tmesh=tmesh, sdim=Ns)

    # ### compute the backward snapshots
    vfun = interp1d(tmesh, vv, axis=0, fill_value='extrapolate')
    vdxoperator, fnctnl = dbs.\
        burgers_bwd_spacedisc(V=femp['V'], ininds=femp['ininds'],
                              diribc=femp['diribc'])
    te = tmesh[-1]

    def vstar(t):
        return iniv.flatten()

    def burger_bwd_rhs(t):
        # TODO: -----------------------------> here we need vstar
        return -fnctnl(vfun(te - t)).flatten() + fnctnl(
            vstar(te - t)).flatten()

    def burger_bwd_nonl(lvec, t):
        vdx = vdxoperator(vfun(te - t))
        return -(vdx * lvec).flatten()

    termiL = np.zeros((Nq - 1, 1))
    bbwdsimudict = dict(iniv=termiL,
                        A=A,
                        M=My,
                        nfunc=burger_bwd_nonl,
                        rhs=burger_bwd_rhs,
                        tmesh=tmesh)

    with dou.Timer('bwd'):
        datastr = 'data/bwdsol_iniv' + inivtype + \
            'Nq{0}Nts{1}nu{2}'.format(Nq, Nts, nu)
        bwdll = dou.\
            load_or_comp(filestr=datastr, comprtn=gpu.time_int_semil,
                         arraytype='dense', comprtnargs=bbwdsimudict,
                         debug=debug)
        # bwdll = gpu.time_int_semil(**bbwdsimudict)
    ll = np.flipud(bwdll)  # flip the to make it forward time
    if adjplotdict is None:
        adjplotdict = dmndct
    plotmat(ll, fignum=1235, **adjplotdict)

    (Lms, _) = gpu.get_genmeasuremat(sol=ll.T, tmesh=tmesh, sdim=Ns)

    # ### compute the projection matrices, i.e. optimal bases
    (lyitUVy, lyUVy, lsitUVs, lsUVs, lyitULy, lyULy, lsitULs, lsULs) = gou.\
        stateadjspatibas(xms=xms, lms=Lms, Ms=Ms, My=My, nspacevecs=hq,
                         ntimevecs=hs, spacebasscheme=spacebasscheme)
    # ## the fwd projection scheme
    AVk, MVk, nonl_red, rhs_red, liftVcoef, projVcoef =\
        gpu.get_spaprjredmod(M=My, A=A, nonl=nfunc, rhs=fwdrhs,
                             Uk=lyitUVy, prjUk=lyUVy)
    hiniv = projVcoef(iniv)

    # ## the bwd projection scheme
    ALk, MLk, bwdl_red, bwdrhs_red, liftLcoef, projLcoef =\
        gpu.get_spaprjredmod(M=My, A=A, nonl=burger_bwd_nonl,
                             rhs=burger_bwd_rhs, Uk=lyitULy, prjUk=lyULy)
    htermiL = projLcoef(termiL)
    red_vdxop = gpu.get_redmatfunc(matfunc=vdxoperator,
                                   ULk=lyitULy,
                                   UVk=lyitUVy)

    # ## the mixed mats
    VLhmy = np.dot(lyitUVy.T, My * lyitULy)
    LVhmy = np.dot(lyitULy.T, My * lyitUVy)

    # ### the tests
    # ## reduced forward problem
    redsimudict = dict(iniv=hiniv,
                       A=AVk,
                       M=MVk,
                       nfunc=nonl_red,
                       rhs=rhs_red,
                       tmesh=redtmesh)
    with dou.Timer('redfwd'):
        print 'solving the reduced  problem (state)...'
        redvv = gpu.time_int_semil(**redsimudict)
    redvv = redvv.reshape((hs, hq))
    plotmat(np.dot(redvv, lyitUVy.T), fignum=1233, **dmndct)
    # ## the reduced fwd as a function
    eva_redfwd = gou.get_eva_fwd(iniv=hiniv,
                                 MV=MVk,
                                 AV=AVk,
                                 MVU=VLhmy,
                                 rhs=rhs_red,
                                 nonlfunc=nonl_red,
                                 tmesh=redtmesh)

    rdvvec = eva_redfwd(np.zeros((hq, hs)))
    rdvv = gou.xvectoX(rdvvec, nq=hq, ns=hs)
    plotmat(np.dot(rdvv.T, lyitUVy.T), fignum=1237, **dmndct)

    # ## the reduced bwd problem
    redbwdsimudict = dict(iniv=htermiL,
                          A=ALk,
                          M=MLk,
                          nfunc=bwdl_red,
                          rhs=bwdrhs_red,
                          tmesh=redtmesh)
    with dou.Timer('redbwd'):
        print 'solving the reduced  problem (adjoint)...'
        redll = gpu.time_int_semil(**redbwdsimudict)
    redll = np.flipud(redll)  # flip the to make it forward time
    redll = redll.reshape((hs, hq))
    plotmat(np.dot(redll, lyitULy.T), fignum=2232, **adjplotdict)

    # ## the reduced bwd problem with reduced fwd solution
    redvfun = interp1d(redtmesh, rdvv, axis=1, fill_value='extrapolate')

    def _liftredvfun(t):
        return np.dot(lyitUVy, redvfun(t))

    def _burger_bwd_rhs(t):
        # TODO: -----------------------------> here we need vstar
        return (-fnctnl(_liftredvfun(te - t)).flatten() +
                fnctnl(vstar(te - t)).flatten())

    def _burger_bwd_nonl(lvec, t):
        vdx = vdxoperator(_liftredvfun(te - t))
        return -(vdx * lvec).flatten()

    ALk, MLk, _bwdl_red, _bwdrhs_red, liftLcoef, projLcoef =\
        gpu.get_spaprjredmod(M=My, A=A, nonl=_burger_bwd_nonl,
                             rhs=_burger_bwd_rhs, Uk=lyitULy, prjUk=lyULy)

    _redbwdsimudict = dict(iniv=htermiL,
                           A=ALk,
                           M=MLk,
                           nfunc=_bwdl_red,
                           rhs=_bwdrhs_red,
                           tmesh=redtmesh)
    redll = gpu.time_int_semil(**_redbwdsimudict)
    redll = np.flipud(redll)  # flip the to make it forward time
    redll = redll.reshape((hs, hq))
    plotmat(np.dot(redll, lyitULy.T), fignum=2233, **adjplotdict)

    redvstarvec = gou.functovec(vstar, redtmesh, projcoef=projVcoef)
    redvstar = gou.xvectoX(redvstarvec, nq=hq, ns=hs)
    _redvstarfun = interp1d(redtmesh,
                            redvstar,
                            axis=1,
                            fill_value='extrapolate')

    # ## the reduced bwd problem with reduced fwd solution
    # ## and manual setup of the coeffs

    def redbvdxl(rlvec, t):
        rvdx = red_vdxop(redvfun(te - t))
        return -np.dot(rvdx, rlvec).flatten()

    def _bbwdrhs(t):
        # TODO: -----------------------------> here we need vstar
        return (-lau.mm_dnssps(LVhmy, redvfun(te - t)).flatten() +
                lau.mm_dnssps(LVhmy, _redvstarfun(t)).flatten())

    redbwdsimudict = dict(iniv=htermiL,
                          A=ALk,
                          M=MLk,
                          nfunc=redbvdxl,
                          rhs=_bbwdrhs,
                          tmesh=redtmesh)
    redll = gpu.time_int_semil(**redbwdsimudict)
    redll = np.flipud(redll)  # flip it to make it forward time
    redll = redll.reshape((hs, hq))
    plotmat(np.dot(redll, lyitULy.T), fignum=2234, **adjplotdict)

    eva_redbwd = gou.get_eva_bwd(vstarvec=redvstarvec,
                                 MLV=LVhmy,
                                 ML=MLk,
                                 AL=ALk,
                                 termiL=htermiL,
                                 tmesh=redtmesh,
                                 vdxoperator=red_vdxop)

    # ## the reduced bwd problem as function
    rdlvec = eva_redbwd(rdvvec)
    rdll = gou.xvectoX(rdlvec, nq=hq, ns=hs)
    plotmat(np.dot(rdll.T, lyitULy.T), fignum=2235, **adjplotdict)

    return None, None