Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 18:11
    goerz milestoned #64
  • 18:11
    goerz labeled #64
  • 18:11
    goerz assigned #64
  • 18:11
    goerz opened #64
  • Dec 09 21:13
    goerz commented #63
  • Dec 09 20:54
    goerz commented #63
  • Dec 09 19:17
    goerz labeled #63
  • Dec 09 19:17
    goerz milestoned #63
  • Dec 09 19:17
    goerz assigned #63
  • Dec 09 19:17
    goerz opened #63
  • Dec 06 10:47
    ajgpitch commented #56
  • Dec 05 00:01

    goerz on v0.5.0

    (compare)

  • Dec 04 23:44
    goerz milestoned #62
  • Dec 04 23:44
    goerz assigned #62
  • Dec 04 23:44
    goerz labeled #62
  • Dec 04 23:44
    goerz opened #62
  • Dec 04 23:38

    goerz on master

    Bump version to 0.5.0 (update H… (compare)

  • Dec 04 23:20
    goerz milestoned #61
  • Dec 04 23:20
    goerz assigned #61
  • Dec 04 23:20
    goerz labeled #61
Michael Goerz
@goerz
So,
def f_oc(fw_states_T, objectives, tau_vals=None, **kwargs):
    return [
        np.abs(
            krotov.functionals.f_tau(
                fw_states_T, objectives, tau_vals, **kwargs
            )
        )
        ** 2
    ]
Johan Winther
@JohanWinther
Then I get
~/miniconda3/envs/qutip-env/lib/python3.7/site-packages/krotov/optimize.py in <listcomp>(.0)
    343             fw_states_T=fw_states_T, objectives=objectives, tau_vals=tau_vals
    344         )
--> 345         chi_norms = [chi.norm() for chi in chi_states]
    346         # normalizing χ improves numerical stability; the norm then has to be
    347         # taken into account when calculating Δϵ

AttributeError: 'numpy.float64' object has no attribute 'norm'
Michael Goerz
@goerz
however, you can just use chis_ss (or equivalently chis_sm): for a single objective, the sum will only contain a single term, which should be what you want
Johan Winther
@JohanWinther
The actual problem I'm working on will later have multiple objectives
Michael Goerz
@goerz
You're passing the routine calculating the functional to chi_constructor... that's not what chi_constructor does
the routine that gets passed to chi_constructor has to return a list of states
(sorry for my misleading anser from a minute ago: f_oc returning a list of floats doesn't make sense)
You should have a function f_oc that returns a the value of the functional as a number (but that doesn't get passed to optimize_pulses)
And then a function chis_oc that returns a list of of states obtained from JT/ϕ\partial J_T / \partial \langle \phi \vert
Johan Winther
@JohanWinther
Ok, and chi_constructor = chis_oc and where to put f_oc?
Michael Goerz
@goerz
f_oc isn't strictly needed, except for an info-hook if you want to print it out
but it's optional: Krotov's method only implicitly depends on the functional
The functional does not have to be evaluated to do the optimization
Johan Winther
@JohanWinther
Ok, now I get it!
Michael Goerz
@goerz
It's all in the boundary condition, the χ\chi-states
👍
Johan Winther
@JohanWinther
I thought you could optimise with respect to a fidelity, but now I know (y).
But is it possible to stop the optimization once a certain value of f_oc is reached?
Michael Goerz
@goerz
Yes
See the documentation in the convergence module
Johan Winther
@JohanWinther
Will do, thank you again! It is very much appreciated!
Michael Goerz
@goerz
No problem!
Johan Winther
@JohanWinther
@goerz Noted, thanks
Tejas Shetty
@TejasAvinashShetty
Dear Dr Goerz, Will you please have a look at #52.
Michael Goerz
@goerz
Hi Tejas! This is going to be quite tricky, unfortunately (see my response on #52)
What parts of the documentation are you most interested in? Do you want to read just the background material (everything after "History" and before "References"), or also the API documentation? The background material is mostly covered in the associated preprint.
Michael Goerz
@goerz
This would be how an epub-version would come out (which Calibre could convert to PDF). As you can see, it's not great.
Tejas Shetty
@TejasAvinashShetty
@goerz Thank you for your reply. I too will try and see if there is any other way.
Tejas Shetty
@TejasAvinashShetty
#52 Thank you @goerz for your fix.
Michael Goerz
@goerz
You're welcome!
Tejas Shetty
@TejasAvinashShetty
Dear Dr @goerz I have tried to use krotov to build a sigmay gate using krotov package. I tried to do this by modifiying the example notebook 01_example_simple_state_to_state.ipynb
Tejas Shetty
@TejasAvinashShetty
So inspired by this code block I modified this code cell to this.
Unfortunately that completely stopped krotov optimization from progressing further.
Tejas Shetty
@TejasAvinashShetty
All the code that I tried is at this Dropbox link
Tejas Shetty
@TejasAvinashShetty
PS : I have changed the projection operators to in another copy of 01_example_simple_state_tostate.ipynb to those derived from eigenvectors of $$ \sigma{y} $$ to plot the populations.
Tejas Shetty
@TejasAvinashShetty
Is there a way to save the output of info_hooks while simultaneously printing the output on the screen? I feel that I can only do only one of these at any given time. The only way I can work around this problem is by using the tee command in bash to save to a file while also printing the output on to the terminal.
Michael Goerz
@goerz
Both info_hooks in krotov, print_debug_information and print_table (https://krotov.readthedocs.io/en/stable/API/krotov.info_hooks.html) have an out parameter
So you have at least three options:
  1. write your own wrapper that does what you want and pass that to info_hook
  2. use a "tee" class like (http://code.activestate.com/recipes/580767-unix-tee-like-functionality-via-a-python-class/) and pass that as out
  3. chain together two calls of e.g. print_table, one with the default out pointing to stdout and one pointing to a file handle.
Timo
@timohillmann
Hi,
after having already quite some experience with Qutip I have only now started to use Krotov for pulse optimization. From qutip I am used to be able to pass the args keyword to mesolve, to change parameters of the time-dependent functions easily. Is krotov currently missing this feature and all parameters in time-depent functions must be defined globally?
Tejas Shetty
@TejasAvinashShetty
Thank you Dr @goerz Will try.
Michael Goerz
@goerz
Hi @timohillmann! This requires a bit of explanation..
Take the first example, cell 2:
def hamiltonian(omega=1.0, ampl0=0.2):
    """Two-level-system Hamiltonian

    Args:
        omega (float): energy separation of the qubit levels
        ampl0 (float): constant amplitude of the driving field
    """
    H0 = -0.5 * omega * qutip.operators.sigmaz()
    H1 = qutip.operators.sigmax()

    def guess_control(t, args):
        return ampl0 * krotov.shapes.flattop(
            t, t_start=0, t_stop=5, t_rise=0.3, func="blackman"
        )

    return [H0, [H1, guess_control]]
First, functions in the Hamiltonian must take both of the parameters t and args, simply because that is what QuTiP requires. As an aside, I actually think this is a design flaw in QuTiP: it would be much better if controls had the form func(t, **args) making args optional.
However, within krotov, time-dependent controls are converted from the callable to a numpy array of control values on the intervals of the time grid very early on, before the actual optimization starts. In this conversion, currently there are no args passed to guess_control. That means that currently, args in any control function is a no-op (which is exactly why I wish QuTiP didn't require it).
I would imagine that in the above example, ampl0 is the kind of parameter you would normally put in args. As you can see, here the value is set by a closure instead (guess_control keeps a hidden reference to ampl0 from its surrounding scope hamiltonian, even after hamiltonian returns). This is the current "official" solution for static parameters in a control. I would not recommend using global variables
There is no fundamental reason we couldn't add an optional args dict to optimize_pulses that gets passed to the control function. I'll consider this for the next version.
Timo
@timohillmann
Hi @goerz! Thank you for the fast reply. While I initially had an similar opinion about args in standard qutip, I am now used to it and have integrated it into my workflow and programming style. I might take a look at optimize_pulses to add the args dict manually. Should I do so, I will report back to you.
Michael Goerz
@goerz
@timohillmann We should be able to accomodate using args. I've opened a ticket for this at qucontrol/krotov#56 and implemented a potential solution. Let's continue the discussion there.