# Superposition Kata

**Superposition** quantum kata is a series of exercises designed
to get you familiar with the concept of superposition and with programming in Q#.
It covers the following topics:
* basic single-qubit and multi-qubit gates,
* superposition,
* flow control and recursion in Q#.

It is recommended to complete the [BasicGates kata](./../BasicGates/BasicGates.ipynb) before this one to get familiar with the basic gates used in quantum computing. The list of basic gates available in Q# can be found at [Microsoft.Quantum.Intrinsic](https://docs.microsoft.com/qsharp/api/qsharp/microsoft.quantum.intrinsic).

Each task is wrapped in one operation preceded by the description of the task.
Your goal is to fill in the blank (marked with `// ...` comments)
with some Q# code that solves the task. To verify your answer, run the cell using Ctrl/⌘+Enter.

The tasks are given in approximate order of increasing difficulty; harder ones are marked with asterisks.

To begin, first prepare this notebook for execution (if you skip this step, you'll get "Syntax does not match any known patterns" error when you try to execute Q# code in the next cells):

```qsharp
%package Microsoft.Quantum.Katas::0.10.1911.1607
```

Microsoft.Quantum.Standard::0.10.1911.1607

Microsoft.Quantum.Katas::0.10.1911.1607

> The package versions in the output of the cell above should always match. If you are running the Notebooks locally and the versions do not match, please install the IQ# version that matches the version of the `Microsoft.Quantum.Katas` package.
>
> How to install the right IQ# version
> For example, if the version of `Microsoft.Quantum.Katas` package above is 0.1.2.3, the installation steps are as follows:
>
> 1. Stop the kernel.
> 2. Uninstall the existing version of IQ#:
>        dotnet tool uninstall microsoft.quantum.iqsharp -g
> 3. Install the matching version:
>        dotnet tool install microsoft.quantum.iqsharp -g --version 0.1.2.3
> 4. Reinstall the kernel:
>        dotnet iqsharp install
> 5. Restart the Notebook.
>

###  Task 1. Plus state.

**Input:** A qubit in the $|0\rangle$ state.

**Goal:**  Change the state of the qubit to $|+\rangle = \frac{1}{\sqrt{2}} \big(|0\rangle + |1\rangle\big)$.

```qsharp
%kata T01_PlusState_Test

operation PlusState (q : Qubit) : Unit {
    H(q);
}
```

    The desired state:
    # wave function for qubits with ids (least to most significant): 0
    ∣0❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    ∣1❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    The actual state:
    # wave function for qubits with ids (least to most significant): 0
    ∣0❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    ∣1❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    Test case passed

    Success!

*Can't come up with a solution? See the explained solution in the [Superposition Workbook](./Workbook_Superposition.ipynb#plus-state).*

###   Task 2. Minus state.

**Input**: A qubit in the $|0\rangle$ state.

**Goal**:  Change the state of the qubit to $|-\rangle = \frac{1}{\sqrt{2}} \big(|0\rangle - |1\rangle\big)$.

```qsharp
%kata T02_MinusState_Test

operation MinusState (q : Qubit) : Unit {
    H(q);
    Z(q);
}
```

    The desired state:
    # wave function for qubits with ids (least to most significant): 0
    ∣0❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    ∣1❭:	-0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ] ---     [  3.14159 rad ]
    The actual state:
    # wave function for qubits with ids (least to most significant): 0
    ∣0❭:	-0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ] ---     [  3.14159 rad ]
    ∣1❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    Test case passed

    Success!

*Can't come up with a solution? See the explained solution in the [Superposition Workbook](./Workbook_Superposition.ipynb#minus-state).*

###   Task 3*. Unequal superposition.

**Inputs:**

1. A qubit in the $|0\rangle$ state.
2. Angle $\alpha$, in radians, represented as `Double`.

**Goal** : Change the state of the qubit to $\cos{α} |0\rangle + \sin{α} |1\rangle$.

  Need a hint? Click here
  Experiment with rotation gates from Microsoft.Quantum.Intrinsic namespace.
  Note that all rotation operators rotate the state by half of its angle argument.

```qsharp
%kata T03_UnequalSuperposition_Test

operation UnequalSuperposition (q : Qubit, alpha : Double) : Unit {
    Ry(2.0 * alpha, q);
}
```

    The desired state for α = 0.5 π
    # wave function for qubits with ids (least to most significant): 0
    ∣0❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    ∣1❭:	 1.000000 +  0.000000 i	 == 	******************** [ 1.000000 ]     --- [  0.00000 rad ]
    The actual state:
    # wave function for qubits with ids (least to most significant): 0
    ∣0❭:	 0.000000 +  0.000000 i	 == 	*                    [ 0.000000 ]     --- [  0.00000 rad ]
    ∣1❭:	 1.000000 +  0.000000 i	 == 	******************** [ 1.000000 ]     --- [  0.00000 rad ]
    Test case passed
    The desired state for α = 0.25 π
    # wave function for qubits with ids (least to most significant): 0
    ∣0❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    ∣1❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    The actual state:
    # wave function for qubits with ids (least to most significant): 0
    ∣0❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    ∣1❭:	 0.707107 +  0.000000 i	 == 	**********           [ 0.500000 ]     --- [  0.00000 rad ]
    Test case passed
    The desired state for α = 0.75 π
    # wave function for qubits with ids (least to most significant): 0
    ∣0❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    ∣1❭:	-0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ] ---     [  3.14159 rad ]
    The actual state:
    # wave function for qubits with ids (least to most significant): 0
    ∣0❭:	-0.707107 +  0.000000 i	 == 	**********           [ 0.500000 ] ---     [  3.14159 rad ]
    ∣1❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    Test case passed
    Testing on hidden test cases...

    Success!

*Can't come up with a solution? See the explained solution in the [Superposition Workbook](./Workbook_Superposition.ipynb#unequal-superposition).*

### Task 4. Superposition of all basis vectors on two qubits.

**Input:** Two qubits in the $|00\rangle$ state (stored in an array of length 2).

**Goal:**  Change the state of the qubits to $|+\rangle \otimes |+\rangle = \frac{1}{2} \big(|00\rangle + |01\rangle + |10\rangle + |11\rangle\big)$.

```qsharp
%kata T04_AllBasisVectors_TwoQubits_Test

operation AllBasisVectors_TwoQubits (qs : Qubit[]) : Unit {
    for (q in qs) {
        H(q);
    }
}
```

    The desired state:
    # wave function for qubits with ids (least to most significant): 0;1
    ∣0❭:	 0.500000 +  0.000000 i	 == 	******               [ 0.250000 ]     --- [  0.00000 rad ]
    ∣1❭:	 0.500000 +  0.000000 i	 == 	******               [ 0.250000 ]     --- [  0.00000 rad ]
    ∣2❭:	 0.500000 +  0.000000 i	 == 	******               [ 0.250000 ]     --- [  0.00000 rad ]
    ∣3❭:	 0.500000 +  0.000000 i	 == 	******               [ 0.250000 ]     --- [  0.00000 rad ]
    The actual state:
    # wave function for qubits with ids (least to most significant): 0;1
    ∣0❭:	 0.500000 +  0.000000 i	 == 	******               [ 0.250000 ]     --- [  0.00000 rad ]
    ∣1❭:	 0.500000 +  0.000000 i	 == 	******               [ 0.250000 ]     --- [  0.00000 rad ]
    ∣2❭:	 0.500000 +  0.000000 i	 == 	******               [ 0.250000 ]     --- [  0.00000 rad ]
    ∣3❭:	 0.500000 +  0.000000 i	 == 	******               [ 0.250000 ]     --- [  0.00000 rad ]
    Test case passed

    Success!

*Can't come up with a solution? See the explained solution in the [Superposition Workbook](./Workbook_Superposition.ipynb#superposition-of-all-basis-vectors-on-two-qubits).*

### Task 5. Superposition of basis vectors with phases.

**Input:** Two qubits in the $|00\rangle$ state (stored in an array of length 2).

**Goal:** Change the state of the qubits to $\frac{1}{2} \big(|00\rangle + i|01\rangle - |10\rangle - i|11\rangle\big)$.

  Need a hint? Click here
  Is this state separable?

📝 $
\frac{1}{2} \big(|00\rangle + i|01\rangle - |10\rangle - i|11\rangle\big)
= \frac{1}{2} \big(|0\rangle - |1\rangle \big) \otimes \big(|0\rangle + i|1\rangle\big)
$

```qsharp
%kata T05_AllBasisVectorsWithPhases_TwoQubits_Test

operation AllBasisVectorsWithPhases_TwoQubits (qs : Qubit[]) : Unit {
    for (q in qs) {
        H(q);
    }
    Z(qs[0]);
    S(qs[1]);
}
```

    The desired state:
    # wave function for qubits with ids (least to most significant): 0;1
    ∣0❭:	 0.500000 +  0.000000 i	 == 	******               [ 0.250000 ]     --- [  0.00000 rad ]
    ∣1❭:	-0.500000 +  0.000000 i	 == 	******               [ 0.250000 ] ---     [  3.14159 rad ]
    ∣2❭:	 0.000000 +  0.500000 i	 == 	******               [ 0.250000 ]    ↑    [  1.57080 rad ]
    ∣3❭:	 0.000000 + -0.500000 i	 == 	******               [ 0.250000 ]    ↓    [ -1.57080 rad ]
    The actual state:
    # wave function for qubits with ids (least to most significant): 0;1
    ∣0❭:	 0.000000 + -0.500000 i	 == 	******               [ 0.250000 ]    ↓    [ -1.57080 rad ]
    ∣1❭:	 0.000000 +  0.500000 i	 == 	******               [ 0.250000 ]    ↑    [  1.57080 rad ]
    ∣2❭:	 0.500000 +  0.000000 i	 == 	******               [ 0.250000 ]     --- [  0.00000 rad ]
    ∣3❭:	-0.500000 +  0.000000 i	 == 	******               [ 0.250000 ] ---     [  3.14159 rad ]
    Test case passed

    Success!

*Can't come up with a solution? See the explained solution in the [Superposition Workbook](./Workbook_Superposition.ipynb#superposition-of-basis-vectors-with-phases).*

### Task 6. Bell state $|\Phi^{+}\rangle$.

**Input:** Two qubits in the $|00\rangle$ state (stored in an array of length 2).

**Goal:**  Change the state of the qubits to $|\Phi^{+}\rangle = \frac{1}{\sqrt{2}} \big (|00\rangle + |11\rangle\big)$.

> You can find detailed coverage of Bell states and their creation [in this blog post](https://blogs.msdn.microsoft.com/uk_faculty_connection/2018/02/06/a-beginners-guide-to-quantum-computing-and-q/).

📝 $$
\begin{bmatrix} 1 \\ 0 \\ 0 \\ 0 \end{bmatrix}
\longrightarrow \frac{1}{\sqrt 2} \begin{bmatrix} 1 \\ 1 \\ 0 \\ 0 \end{bmatrix}
\longrightarrow \frac{1}{\sqrt 2} \begin{bmatrix} 1 \\ 0 \\ 0 \\ 1 \end{bmatrix}
$$

```qsharp
%kata T06_BellState_Test

operation BellState (qs : Qubit[]) : Unit {
    H(qs[0]);
    CNOT(qs[0], qs[1]);
}
```

    The desired state:
    # wave function for qubits with ids (least to most significant): 0;1
    ∣0❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    ∣1❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    ∣2❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    ∣3❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    The actual state:
    # wave function for qubits with ids (least to most significant): 0;1
    ∣0❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    ∣1❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    ∣2❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    ∣3❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    Test case passed

    Success!

*Can't come up with a solution? See the explained solution in the [Superposition Workbook](./Workbook_Superposition.ipynb#bell-state).*

###  Task 7. All Bell states.

**Inputs:**

1. Two qubits in the $|00\rangle$ state (stored in an array of length 2).
2. An integer index.

**Goal:**  Change the state of the qubits to one of the Bell states, based on the value of index:

  <col width="50"/>
  <col width="200"/>

    Index
    State

    0
    $|\Phi^{+}\rangle = \frac{1}{\sqrt{2}} \big (|00\rangle + |11\rangle\big)$

    1
    $|\Phi^{-}\rangle = \frac{1}{\sqrt{2}} \big (|00\rangle - |11\rangle\big)$

    2
    $|\Psi^{+}\rangle = \frac{1}{\sqrt{2}} \big (|01\rangle + |10\rangle\big)$

    3
    $|\Psi^{-}\rangle = \frac{1}{\sqrt{2}} \big (|01\rangle - |10\rangle\big)$

```qsharp
%kata T07_AllBellStates_Test

operation AllBellStates (qs : Qubit[], index : Int) : Unit {
    H(qs[0]);
    CNOT(qs[0], qs[1]);

    if (index % 2 == 1) {
        Z(qs[1]);
    }
    if (index >= 2) {
        X(qs[0]);
    }
}
```

    The desired state for index = 0
    # wave function for qubits with ids (least to most significant): 0;1
    ∣0❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    ∣1❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    ∣2❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    ∣3❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    The actual state:
    # wave function for qubits with ids (least to most significant): 0;1
    ∣0❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    ∣1❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    ∣2❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    ∣3❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    Test case passed
    The desired state for index = 1
    # wave function for qubits with ids (least to most significant): 0;1
    ∣0❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    ∣1❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    ∣2❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    ∣3❭:	-0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ] ---     [  3.14159 rad ]
    The actual state:
    # wave function for qubits with ids (least to most significant): 0;1
    ∣0❭:	-0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ] ---     [  3.14159 rad ]
    ∣1❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    ∣2❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    ∣3❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    Test case passed
    The desired state for index = 2
    # wave function for qubits with ids (least to most significant): 0;1
    ∣0❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    ∣1❭:	-0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ] ---     [  3.14159 rad ]
    ∣2❭:	-0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ] ---     [  3.14159 rad ]
    ∣3❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    The actual state:
    # wave function for qubits with ids (least to most significant): 0;1
    ∣0❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    ∣1❭:	-0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ] ---     [  3.14159 rad ]
    ∣2❭:	-0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ] ---     [  3.14159 rad ]
    ∣3❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    Test case passed
    The desired state for index = 3
    # wave function for qubits with ids (least to most significant): 0;1
    ∣0❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    ∣1❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    ∣2❭:	-0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ] ---     [  3.14159 rad ]
    ∣3❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    The actual state:
    # wave function for qubits with ids (least to most significant): 0;1
    ∣0❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    ∣1❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    ∣2❭:	-0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ] ---     [  3.14159 rad ]
    ∣3❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    Test case passed

    Success!

*Can't come up with a solution? See the explained solution in the [Superposition Workbook](./Workbook_Superposition.ipynb#all-bell-states).*

### Task 8. Greenberger–Horne–Zeilinger state.

**Input:** $N$ ($N \ge 1$) qubits in the $|0 \dots 0\rangle$ state (stored in an array of length $N$).

**Goal:**  Change the state of the qubits to the GHZ state $\frac{1}{\sqrt{2}} \big (|0\dots0\rangle + |1\dots1\rangle\big)$.

> For the syntax of flow control statements in Q#, see [the Q# documentation](https://docs.microsoft.com/quantum/language/statements#control-flow).

📝 $$
\begin{align}
|0\rangle^{\otimes N}
& \xrightarrow{\text{H}(0)} \frac{1}{\sqrt{2}} \big( |0\rangle + |1\rangle \big) \otimes |0\rangle^{\otimes N-1}
= \frac{1}{\sqrt{2}} \big( |00\rangle + |10\rangle \big) \otimes |0\rangle^{\otimes N-2} \\
& \xrightarrow{\text{CNOT}(0,1)} \frac{1}{\sqrt{2}} \big( |00\rangle + |11\rangle \big) \otimes |0\rangle^{\otimes N-2}
= \frac{1}{\sqrt{2}} \big( |000\rangle + |110\rangle \big) \otimes |0\rangle^{\otimes N-3} \\
& \xrightarrow{\text{CNOT}(0,2)} \frac{1}{\sqrt{2}} \big( |000\rangle + |111\rangle \big) \otimes |0\rangle^{\otimes N-3} \\
& \dots \phantom{\frac{1}{\sqrt{2}}} \\
& \xrightarrow{\text{CNOT}(0,N-1)} \frac{1}{\sqrt{2}} \big( |0\rangle^{\otimes N} + |1\rangle^{\otimes N} \big) \\
\end{align}
$$

```qsharp
%kata T08_GHZ_State_Test

operation GHZ_State (qs : Qubit[]) : Unit {
    H(qs[0]);
    for (i in 1 .. Length(qs) - 1) {
        CNOT(qs[0], qs[i]);
    }
}
```

    The desired state for N = 1
    # wave function for qubits with ids (least to most significant): 0
    ∣0❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    ∣1❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    The actual state:
    # wave function for qubits with ids (least to most significant): 0
    ∣0❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    ∣1❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    Test case passed
    The desired state for N = 2
    # wave function for qubits with ids (least to most significant): 0;1
    ∣0❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    ∣1❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    ∣2❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    ∣3❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    The actual state:
    # wave function for qubits with ids (least to most significant): 0;1
    ∣0❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    ∣1❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    ∣2❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    ∣3❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    Test case passed
    Testing on hidden test cases...

    Success!

### Task 9. Superposition of all basis vectors.

**Input:** $N$ ($N \ge 1$) qubits in the $|0 \dots 0\rangle$ state.

**Goal:**  Change the state of the qubits to an equal superposition of all basis vectors $\frac{1}{\sqrt{2^N}} \big (|0 \dots 0\rangle + \dots + |1 \dots 1\rangle\big)$.

  Need a hint? Click here
  Is this state separable?

📝 $$
\frac{1}{\sqrt{2^N}} \big (|0 \dots 0\rangle + \dots + |1 \dots 1\rangle\big) =
\left( \frac{1}{\sqrt 2} \big (|0\rangle + |1\rangle \big) \right) ^{\otimes N}
$$

```qsharp
%kata T09_AllBasisVectorsSuperposition_Test

operation AllBasisVectorsSuperposition (qs : Qubit[]) : Unit {
    for (i in 0 .. Length(qs) - 1) {
        H(qs[i]);
    }
}
```

    The desired state for N = 1
    # wave function for qubits with ids (least to most significant): 0
    ∣0❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    ∣1❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    The actual state:
    # wave function for qubits with ids (least to most significant): 0
    ∣0❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    ∣1❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    Test case passed
    The desired state for N = 2
    # wave function for qubits with ids (least to most significant): 0;1
    ∣0❭:	 0.500000 +  0.000000 i	 == 	******               [ 0.250000 ]     --- [  0.00000 rad ]
    ∣1❭:	 0.500000 +  0.000000 i	 == 	******               [ 0.250000 ]     --- [  0.00000 rad ]
    ∣2❭:	 0.500000 +  0.000000 i	 == 	******               [ 0.250000 ]     --- [  0.00000 rad ]
    ∣3❭:	 0.500000 +  0.000000 i	 == 	******               [ 0.250000 ]     --- [  0.00000 rad ]
    The actual state:
    # wave function for qubits with ids (least to most significant): 0;1
    ∣0❭:	 0.500000 +  0.000000 i	 == 	******               [ 0.250000 ]     --- [  0.00000 rad ]
    ∣1❭:	 0.500000 +  0.000000 i	 == 	******               [ 0.250000 ]     --- [  0.00000 rad ]
    ∣2❭:	 0.500000 +  0.000000 i	 == 	******               [ 0.250000 ]     --- [  0.00000 rad ]
    ∣3❭:	 0.500000 +  0.000000 i	 == 	******               [ 0.250000 ]     --- [  0.00000 rad ]
    Test case passed
    Testing on hidden test cases...

    Success!

###  Task 10. Superposition of all even or all odd numbers.

**Inputs:**

1. $N$ ($N \ge 1$) qubits in the $|0 \dots 0\rangle$ state (stored in an array of length $N$).
2. A boolean `isEven`.

**Goal:**  Prepare a superposition of all *even* numbers if `isEven` is `true`, or of all *odd* numbers if `isEven` is `false`.
A basis state encodes an integer number using [big-endian](https://en.wikipedia.org/wiki/Endianness) binary notation: state $|01\rangle$ corresponds to the integer $1$, and state $|10 \rangle$ - to the integer $2$.

> For example, for $N = 2$ and `isEven = false` you need to prepare superposition $\frac{1}{\sqrt{2}} \big (|01\rangle + |11\rangle\big )$,
and for $N = 2$ and `isEven = true` - superposition $\frac{1}{\sqrt{2}} \big (|00\rangle + |10\rangle\big )$.

📝
$$
\begin{cases}
\left( \frac{1}{\sqrt 2} \big (|0\rangle + |1\rangle \big) \right) ^{\otimes N-1} \otimes |0\rangle, & \text{if } \texttt{isEven} \\
\left( \frac{1}{\sqrt 2} \big (|0\rangle + |1\rangle \big) \right) ^{\otimes N-1} \otimes |1\rangle, & \text{if } \texttt{!isEven}
\end{cases}
$$

```qsharp
%kata T10_EvenOddNumbersSuperposition_Test

operation EvenOddNumbersSuperposition (qs : Qubit[], isEven : Bool) : Unit {
    let len = Length(qs);
    for (i in 0 .. len - 2) {
        H(qs[i]);
    }
    if (!isEven) {
        X(qs[len - 1]);
    }
}
```

    /snippet_.qs(7,9): warning QS3301: Deprecated syntax. Use "not" to denote the logical NOT operator.
    The desired state for N = 1, isEven = False
    # wave function for qubits with ids (least to most significant): 0
    ∣0❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    ∣1❭:	 1.000000 +  0.000000 i	 == 	******************** [ 1.000000 ]     --- [  0.00000 rad ]
    The actual state:
    # wave function for qubits with ids (least to most significant): 0
    ∣0❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    ∣1❭:	 1.000000 +  0.000000 i	 == 	******************** [ 1.000000 ]     --- [  0.00000 rad ]
    Test case passed
    The desired state for N = 1, isEven = True
    # wave function for qubits with ids (least to most significant): 0
    ∣0❭:	 1.000000 +  0.000000 i	 == 	******************** [ 1.000000 ]     --- [  0.00000 rad ]
    ∣1❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    The actual state:
    # wave function for qubits with ids (least to most significant): 0
    ∣0❭:	 1.000000 +  0.000000 i	 == 	******************** [ 1.000000 ]     --- [  0.00000 rad ]
    ∣1❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    Test case passed
    The desired state for N = 2, isEven = False
    # wave function for qubits with ids (least to most significant): 0;1
    ∣0❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    ∣1❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    ∣2❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    ∣3❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    The actual state:
    # wave function for qubits with ids (least to most significant): 0;1
    ∣0❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    ∣1❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    ∣2❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    ∣3❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    Test case passed
    The desired state for N = 2, isEven = True
    # wave function for qubits with ids (least to most significant): 0;1
    ∣0❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    ∣1❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    ∣2❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    ∣3❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    The actual state:
    # wave function for qubits with ids (least to most significant): 0;1
    ∣0❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    ∣1❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    ∣2❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    ∣3❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    Test case passed
    Testing on hidden test cases...

    Success!

*Can't come up with a solution? See the explained solution in the [Superposition Workbook](./Workbook_Superposition_Part2.ipynb#superposition-of-all-even-or-all-odd-numbers).*

### Task 11*. $\frac{1}{\sqrt{3}} \big(|00\rangle + |01\rangle + |10\rangle\big)$ state.

**Input:** Two qubits in the $|00\rangle$ state.

**Goal:**  Change the state of the qubits to $\frac{1}{\sqrt{3}} \big(|00\rangle + |01\rangle + |10\rangle\big)$.

  Need a hint? Click here
  If you need trigonometric functions, you can find them in Microsoft.Quantum.Math namespace; you'll need to add
open Microsoft.Quantum.Math;
 to the code before the operation definition.

📝 係数 $1/\sqrt{3}$ の成分がほしいので、まずは1つ作るところから考える。$H = R_y(\pi)$ だったのを参考にすると、適当な角度 $\theta \in [0, \pi/2] $ をとって

$$
R_y(\theta) |0\rangle = \cos\frac{\theta}{2} |0\rangle + \sin\frac{\theta}{2} |1\rangle
= \frac{1}{\sqrt 3} |0\rangle + {\sqrt \frac{2}{3}} |1\rangle
$$

とできる。このとき $\theta = 2 \arccos 1/\sqrt{3}$。この $R_y(\theta)$ を第0キュビットにかけると、状態は

$$
\left(R_y(\theta) \otimes I \right) |00\rangle =
\frac{1}{\sqrt 3} |00\rangle + {\sqrt \frac{2}{3}} |10\rangle
$$

となる。${\sqrt {2/3}} |10\rangle$ の第1キュビットに $H$ をかけてやればよさそう。

$$
\begin{align}
\frac{1}{\sqrt 3} |00\rangle + {\sqrt \frac{2}{3}} |10\rangle
&\xrightarrow{\text{C-H}}
\frac{1}{\sqrt 3} |00\rangle + {\sqrt \frac{2}{3}} |1\rangle \otimes \frac{1}{\sqrt{2}} \big( |0\rangle + |1\rangle \big) \\
& =
\frac{1}{\sqrt 3} \big( |00\rangle + |10\rangle + |11\rangle \big)
\end{align}
$$

Goal と比較すると、さらに $|11\rangle$ を $|01\rangle$ にしたいので、

$$
\xrightarrow{\text{CNOT}}
\frac{1}{\sqrt 3} \big( |00\rangle + |01\rangle + |10\rangle \big)
$$

```qsharp
%kata T11_ThreeStates_TwoQubits_Test

open Microsoft.Quantum.Math;

operation ThreeStates_TwoQubits (qs : Qubit[]) : Unit {
    let theta = 2.0 * ArcCos(Sqrt(1.0 / 3.0));
    Ry(theta, qs[0]);
    Controlled H([qs[0]], qs[1]);
    CNOT(qs[1], qs[0]);
}
```

    The desired state:
    # wave function for qubits with ids (least to most significant): 0;1
    ∣0❭:	 0.577350 +  0.000000 i	 == 	*******              [ 0.333333 ]     --- [  0.00000 rad ]
    ∣1❭:	 0.577350 +  0.000000 i	 == 	*******              [ 0.333333 ]     --- [  0.00000 rad ]
    ∣2❭:	 0.577350 +  0.000000 i	 == 	*******              [ 0.333333 ]     --- [  0.00000 rad ]
    ∣3❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    The actual state:
    # wave function for qubits with ids (least to most significant): 0;1
    ∣0❭:	 0.577350 +  0.000000 i	 == 	*******              [ 0.333333 ]     --- [  0.00000 rad ]
    ∣1❭:	 0.577350 +  0.000000 i	 == 	*******              [ 0.333333 ]     --- [  0.00000 rad ]
    ∣2❭:	 0.577350 +  0.000000 i	 == 	*******              [ 0.333333 ]     --- [  0.00000 rad ]
    ∣3❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    Test case passed

    Success!

📝 解答 `ReferenceImplementations.qs` を見ると、[`ControlledOnInt`](https://docs.microsoft.com/en-us/qsharp/api/qsharp/microsoft.quantum.canon.controlledonint?view=qsharp-preview) が使われている。通常の `Controlled Op(control, target)` は「`control` が `1` のとき `target` に `Op` を適用」だが、`(ControlledOnInt(num, Op))(control, target)` は「`control` が `num` のとき `target` に `Op` を適用」らしい。

### Task 12*. Hardy state.

**Input:** Two qubits in the $|00\rangle$ state.

**Goal:**  Change the state of the qubits to $\frac{1}{\sqrt{12}} \big(3|00\rangle + |01\rangle + |10\rangle + |11\rangle\big)$.

  Need a hint? Click here
  If you need trigonometric functions, you can find them in Microsoft.Quantum.Math namespace; you'll need to add
open Microsoft.Quantum.Math;
 to the code before the operation definition.

📝 前の Task で $R_y$ や $H$ を使って同じ係数 $1/\sqrt{3}$ を2つ作った流れを参考にする。$\alpha = 2 \arccos \sqrt{5/6}$ として、

$$
\begin{align}
    |00\rangle
    &\xrightarrow{R_y(\alpha) \otimes I}
    \sqrt\frac{5}{6} |00\rangle + \frac{1}{\sqrt6} |10\rangle \\
    &\xrightarrow{\text{C-}H}
    \sqrt\frac{5}{6} |00\rangle + \frac{1}{\sqrt6} |1\rangle \otimes \frac{1}{\sqrt2} \big( |0\rangle + |1\rangle \big) \\
    &=
    \sqrt\frac{5}{6} |00\rangle + \frac{1}{\sqrt{12}} \big( |10\rangle + |11\rangle \big)
\end{align}
$$

`ControlledOnInt(0, Ry)` を使って $|00\rangle$ の第1ビットにだけ $R_y(\beta)$ を作用させ、

$$
\begin{align}
    &\xrightarrow{\text{C-}R_y(\beta)}
    \sqrt\frac{5}{6} |0\rangle \otimes \big( \frac{3}{\sqrt{10}} |0\rangle + \frac{1}{\sqrt{10}} |1\rangle \big)
        + \frac{1}{\sqrt{12}} \big( |10\rangle + |11\rangle \big) \\
    & =
    \frac{1}{\sqrt{12}} \big( 3|00\rangle + |01\rangle + |10\rangle + |11\rangle \big)
\end{align}
$$

とできる。ただし $\beta = 2 \arccos \left(3/\sqrt{10} \right)$。

```qsharp
%kata T12_Hardy_State_Test

open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Math;

operation Hardy_State (qs : Qubit[]) : Unit {
    let alpha = 2.0 * ArcCos(Sqrt(5.0 / 6.0));
    Ry(alpha, qs[0]);
    Controlled H([qs[0]], qs[1]);

    let beta = 2.0 * ArcCos(3.0 / Sqrt(10.0));
    (ControlledOnInt(0, Ry))([qs[0]], (beta, qs[1]));
}
```

    /snippet_.qs(2,6): warning QS6003: The namespace is already open.
    The desired state:
    # wave function for qubits with ids (least to most significant): 0;1
    ∣0❭:	 0.866025 +  0.000000 i	 == 	****************     [ 0.750000 ]     --- [  0.00000 rad ]
    ∣1❭:	 0.288675 +  0.000000 i	 == 	**                   [ 0.083333 ]     --- [  0.00000 rad ]
    ∣2❭:	 0.288675 +  0.000000 i	 == 	**                   [ 0.083333 ]     --- [  0.00000 rad ]
    ∣3❭:	 0.288675 +  0.000000 i	 == 	**                   [ 0.083333 ]     --- [  0.00000 rad ]
    The actual state:
    # wave function for qubits with ids (least to most significant): 0;1
    ∣0❭:	 0.866025 +  0.000000 i	 == 	****************     [ 0.750000 ]     --- [  0.00000 rad ]
    ∣1❭:	 0.288675 +  0.000000 i	 == 	**                   [ 0.083333 ]     --- [  0.00000 rad ]
    ∣2❭:	 0.288675 +  0.000000 i	 == 	**                   [ 0.083333 ]     --- [  0.00000 rad ]
    ∣3❭:	 0.288675 +  0.000000 i	 == 	**                   [ 0.083333 ]     --- [  0.00000 rad ]
    Test case passed

    Success!

### Task 13. Superposition of $|0 \dots 0\rangle$ and the given bit string.

**Inputs:**

1. $N$ ($N \ge 1$) qubits in the $|0 \dots 0\rangle$ state.
2. A bit string of length $N$ represented as `Bool[]`. Bit values `false` and `true` correspond to $|0\rangle$ and $|1\rangle$ states. You are guaranteed that the first bit of the bit string is `true`.

**Goal:**  Change the state of the qubits to an equal superposition of $|0 \dots 0\rangle$ and the basis state given by the bit string.

> For example, for the bit string `[true, false]` the state required is $\frac{1}{\sqrt{2}}\big(|00\rangle + |10\rangle\big)$.

📝 0番目のビットは必ず `true` なので、0番目のキュビットに H をかけて
$$
|0 \dots 0\rangle \longrightarrow \frac{1}{\sqrt{2}}\big( |00 \dots 0\rangle + |\color{blue}{1}0 \dots 0\rangle \big)
$$

1番目のビットが `true` のとき、第2項の1番目のキュビットを反転させればよい。0番目のキュビットを制御側とした CNOT を使えば、

$$
\frac{1}{\sqrt{2}}\big( |00 \dots 0\rangle + |10 \dots 0\rangle \big) \longrightarrow \frac{1}{\sqrt{2}}\big( |000 \dots 0\rangle + |\color{blue}{11}0 \dots 0\rangle \big)
$$

一方、1番目のビットが `false` の場合はそのままで

$$
\frac{1}{\sqrt{2}}\big( |00 \dots 0\rangle + |10 \dots 0\rangle \big) = \frac{1}{\sqrt{2}}\big( |000 \dots 0\rangle + |\color{blue}{10}0 \dots 0\rangle \big)
$$

以下繰り返し。

```qsharp
%kata T13_ZeroAndBitstringSuperposition_Test

operation ZeroAndBitstringSuperposition (qs : Qubit[], bits : Bool[]) : Unit {
    H(qs[0]);
    for (i in 1 .. Length(qs) - 1) {
        if (bits[i]) {
            CNOT(qs[0], qs[i]);
        }
    }
}
```

    The desired state for bits = [True]
    # wave function for qubits with ids (least to most significant): 0
    ∣0❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    ∣1❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    The actual state:
    # wave function for qubits with ids (least to most significant): 0
    ∣0❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    ∣1❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    Test case passed
    The desired state for bits = [True,True]
    # wave function for qubits with ids (least to most significant): 0;1
    ∣0❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    ∣1❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    ∣2❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    ∣3❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    The actual state:
    # wave function for qubits with ids (least to most significant): 0;1
    ∣0❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    ∣1❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    ∣2❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    ∣3❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    Test case passed
    The desired state for bits = [True,False]
    # wave function for qubits with ids (least to most significant): 0;1
    ∣0❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    ∣1❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    ∣2❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    ∣3❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    The actual state:
    # wave function for qubits with ids (least to most significant): 0;1
    ∣0❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    ∣1❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    ∣2❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    ∣3❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    Test case passed
    Testing on hidden test cases...

    Success!

### Task 14. Superposition of two bit strings.

**Inputs:**

1. $N$ ($N \ge 1$) qubits in the $|0 \dots 0\rangle$ state.
2. Two bit strings of length $N$ represented as `Bool[]`s. Bit values `false` and `true` correspond to $|0\rangle$ and $|1\rangle$ states. You are guaranteed that the two bit strings differ in at least one bit.

**Goal:**  Change the state of the qubits to an equal superposition of the basis states given by the bit strings.

> For example, for bit strings `[false, true, false]` and `[false, false, true]` the state required is $\frac{1}{\sqrt{2}}\big(|010\rangle + |001\rangle\big)$.

> If you need to define any helper functions, you'll need to create an extra code cell for it and execute it before returning to this cell.

📝 最初に `bits1[k] != bits2[k]` なるインデックス `k` を探してそこに H をかけ、`qs[k]` を制御キュビットとして前問のように順次セットしていけばよい。

```qsharp
open Microsoft.Quantum.Canon;

operation SetFromBits (qs : Qubit[], bits : Bool[], k: Int) : Unit {
    let kValue = bits[k] ? 1 | 0;

    for (i in 0 .. Length(qs) - 1) {
        if (i != k and bits[i]) {
            (ControlledOnInt(kValue, X))([qs[k]],  qs[i]);
        }
    }
}
```

    /snippet_.qs(1,90): warning QS6003: The namespace is already open.

SetFromBits

```qsharp
%kata T14_TwoBitstringSuperposition_Test

open Microsoft.Quantum.Arrays;
open Microsoft.Quantum.Logical;

operation TwoBitstringSuperposition (qs : Qubit[], bits1 : Bool[], bits2 : Bool[]) : Unit {
    let k = IndexOf(NotEqualB, Zip(bits1, bits2));
    H(qs[k]);

    SetFromBits(qs, bits1, k);
    SetFromBits(qs, bits2, k);
}
```

    The desired state for bits1 = [True], bits2 = [False]
    # wave function for qubits with ids (least to most significant): 0
    ∣0❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    ∣1❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    The actual state:
    # wave function for qubits with ids (least to most significant): 0
    ∣0❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    ∣1❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    Test case passed
    The desired state for bits1 = [False,True], bits2 = [True,False]
    # wave function for qubits with ids (least to most significant): 0;1
    ∣0❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    ∣1❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    ∣2❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    ∣3❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    The actual state:
    # wave function for qubits with ids (least to most significant): 0;1
    ∣0❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    ∣1❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    ∣2❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    ∣3❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    Test case passed
    Testing on hidden test cases...

    Success!

### Task 15*. Superposition of four bit strings.

**Inputs:**

1. $N$ ($N \ge 1$) qubits in the $|0 \dots 0\rangle$ state.
2. Four bit strings of length $N$, represented as `Bool[][]` `bits`. `bits` is an $4 \times N$ which describes the bit strings as follows: `bits[i]` describes the `i`-th bit string and has $N$ elements. You are guaranteed that all four bit strings will be distinct.

**Goal:**  Change the state of the qubits to an equal superposition of the four basis states given by the bit strings.

> For example, for $N = 3$ and `bits = [[false, true, false], [true, false, false], [false, false, true], [true, true, false]]` the state required is $\frac{1}{2}\big(|010\rangle + |100\rangle + |001\rangle + |110\rangle\big)$.

  Need a hint? Click here
  Remember that you can allocate extra qubits. If you do, you'll need to return them to the $|0\rangle$ state before releasing them.

📝 hint に従い、[`using` 文](https://docs.microsoft.com/en-us/quantum/language/statements?view=qsharp-preview#clean-qubits)で補助キュビットを用意して使ってみる。4状態を区別するには2キュビットで十分。

```qsharp
%kata T15_FourBitstringSuperposition_Test

operation FourBitstringSuperposition (qs : Qubit[], bits : Bool[][]) : Unit {
    using (ancillae = Qubit[2]) {
        H(ancillae[0]);
        H(ancillae[1]);

        let N = Length(qs);
        for (i in 0 .. 3) {
            for (j in 0 .. N - 1) {
                if (bits[i][j]) {
                    (ControlledOnInt(i, X))(ancillae, qs[j]);
                }
            }
        }

        // using 文を抜ける前にすべて |0> に戻す必要がある
        for (i in 0 .. 3) {
            if (i % 2 == 1) {
                (ControlledOnBitString(bits[i], X))(qs, ancillae[0]);
            }
            if (i / 2 == 1) {
                (ControlledOnBitString(bits[i], X))(qs, ancillae[1]);
            }
        }
    }
}
```

    The desired state for bits = [[False,False],[False,True],[True,False],[True,True]]
    # wave function for qubits with ids (least to most significant): 0;1
    ∣0❭:	 0.500000 +  0.000000 i	 == 	******               [ 0.250000 ]     --- [  0.00000 rad ]
    ∣1❭:	 0.500000 +  0.000000 i	 == 	******               [ 0.250000 ]     --- [  0.00000 rad ]
    ∣2❭:	 0.500000 +  0.000000 i	 == 	******               [ 0.250000 ]     --- [  0.00000 rad ]
    ∣3❭:	 0.500000 +  0.000000 i	 == 	******               [ 0.250000 ]     --- [  0.00000 rad ]
    The actual state:
    # wave function for qubits with ids (least to most significant): 0;1
    ∣0❭:	 0.500000 +  0.000000 i	 == 	******               [ 0.250000 ]     --- [  0.00000 rad ]
    ∣1❭:	 0.500000 +  0.000000 i	 == 	******               [ 0.250000 ]     --- [  0.00000 rad ]
    ∣2❭:	 0.500000 +  0.000000 i	 == 	******               [ 0.250000 ]     --- [  0.00000 rad ]
    ∣3❭:	 0.500000 +  0.000000 i	 == 	******               [ 0.250000 ]     --- [  0.00000 rad ]
    Test case passed
    Testing on hidden test cases...

    Success!

📝 `using` 文は、ここから抜ける前に補助キュビットをすべて $|0\rangle$ に戻しておかないとエラーになる。この戻し方は、解答を見ないとわからなかった。[`ResetAll`](https://docs.microsoft.com/en-us/qsharp/api/qsharp/microsoft.quantum.intrinsic.resetall?view=qsharp-preview) というそれっぽい操作があるが、これは内部で測定をするらしく、状態が収束してしまう。

📝 前問の方針を応用してもできそう？ 4 つのビット列はたかだか 3 つの桁 `k01`, `k02`, `k03` で区別できるので、それらを制御キュビットとして状態をセットしていく方法。

### Task 16**. W state on $2^k$ qubits.

**Input:** $N = 2^k$ qubits in the $|0 \dots 0\rangle$ state.

**Goal:**  Change the state of the qubits to the [W state](https://en.wikipedia.org/wiki/W_state) - an equal superposition of $N$ basis states on $N$ qubits which have Hamming weight of 1.

> For example, for $N = 4$ the required state is $\frac{1}{2}\big(|1000\rangle + |0100\rangle + |0010\rangle + |0001\rangle\big)$.

  Need a hint? Click here
  You can use Controlled modifier to perform arbitrary controlled gates.

```qsharp
%kata T16_WState_PowerOfTwo_Test

open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Convert;
open Microsoft.Quantum.Math;

operation WState_PowerOfTwo (qs : Qubit[]) : Unit {
    let N = Length(qs);
    let k = Ceiling(Lg(IntAsDouble(N)));

    using (anc = Qubit[k]) {
        ApplyToEach(H, anc); // 各キュビットに H をかけて均等な重ね合わせにする
        for (i in 0 .. N - 1) {
            (ControlledOnInt(i, X))(anc, qs[i]);
        }

        // anc をすべて |0> に戻す
        for (i in 0 .. N - 1) {
            let bits = IntAsBoolArray(i, k);
            for (j in 0 .. k - 1) {
                if (bits[j]) {
                    // (ControlledOnInt(2 ^ i, X))(qs, anc[j]);
                    // qs[i] の1つを見るだけで状態を判別できるので、下のように書ける
                    (ControlledOnInt(1, X))([qs[i]], anc[j]);
                }
            }
        }
    }
}
```

    /snippet_.qs(2,6): warning QS6003: The namespace is already open.
    The desired state for N = 1
    # wave function for qubits with ids (least to most significant): 0
    ∣0❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    ∣1❭:	 1.000000 +  0.000000 i	 == 	******************** [ 1.000000 ]     --- [  0.00000 rad ]
    The actual state:
    # wave function for qubits with ids (least to most significant): 0
    ∣0❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    ∣1❭:	 1.000000 +  0.000000 i	 == 	******************** [ 1.000000 ]     --- [  0.00000 rad ]
    Test case passed
    The desired state for N = 2
    # wave function for qubits with ids (least to most significant): 0;1
    ∣0❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    ∣1❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    ∣2❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    ∣3❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    The actual state:
    # wave function for qubits with ids (least to most significant): 0;1
    ∣0❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    ∣1❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    ∣2❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    ∣3❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    Test case passed
    Testing on hidden test cases...

    Success!

### Task 17**. W state on an arbitrary number of qubits.

**Input:** $N$ qubits in the $|0 \dots 0\rangle$ state ($N$ is not necessarily a power of 2).

**Goal:**  Change the state of the qubits to the [W state](https://en.wikipedia.org/wiki/W_state) - an equal superposition of $N$ basis states on $N$ qubits which have Hamming weight of 1.

> For example, for $N = 3$ the required state is $\frac{1}{\sqrt{3}}\big(|100\rangle + |010\rangle + |001\rangle\big)$.

  Need a hint? Click here
  You can modify the signature of the given operation to specify its controlled specialization.

📝 $N$ キュビットからなる W state を $|W_N\rangle$ とすると

$$
\begin{align}
|W_N\rangle &= \frac{1}{\sqrt{N}}\big(|100\dots0\rangle + |010\dots0\rangle + \dots + |000\dots1\rangle \big)
\end{align}
$$

であり、特に $|W_0\rangle = |1\rangle$。

$N > 1$ のとき、Task 11 や Task 12 の操作を参考にして、

$$
R_y (\theta_N) |0\rangle = \sqrt\frac{N - 1}{N} |0\rangle + \sqrt\frac{1}{N} |1\rangle
$$

なるキュビットを用意できる（$\theta_N = 2\arcsin1/\sqrt{N}$）。

$|0\rangle ^{\otimes N-1} \rightarrow |W_{N-1}\rangle$ とする操作を、用意したキュビットが $|0\rangle$ のときに適用させれば、

$$
\begin{align}
|0\rangle ^{\otimes N-1} \otimes \left( \sqrt\frac{N - 1}{N} |0\rangle + \sqrt\frac{1}{N} |1\rangle \right)
&\longrightarrow
    |W_{N-1}\rangle \otimes \sqrt\frac{N - 1}{N} |0\rangle
    + |0\rangle ^{\otimes N-1} \otimes \sqrt\frac{1}{N} |1\rangle \\
&=
    \frac{1}{\sqrt{N-1}}\big(|100\dots0\rangle + |010\dots0\rangle + \dots + |000\dots1\rangle \big)
        \otimes \sqrt\frac{N - 1}{N} |0\rangle
    + \frac{1}{\sqrt{N}} |000\dots01\rangle \\
&=
    \frac{1}{\sqrt{N}}\big(|100\dots00\rangle + |010\dots00\rangle + \dots + |000\dots10\rangle + |000\dots01\rangle \big)\\
&= |W_N\rangle
\end{align}
$$

となり、$|W_N\rangle$ が得られる。

```qsharp
%kata T17_WState_Arbitrary_Test

open Microsoft.Quantum.Convert;
open Microsoft.Quantum.Math;

operation WState_Arbitrary (qs : Qubit[]) : Unit is Ctl {
    let N = Length(qs);

    if (N == 1) {
        X(qs[0]);
    } else {
        let theta = 2.0 * ArcSin(1.0 / Sqrt(IntAsDouble(N)));
        Ry(theta, qs[N - 1]);

        // qs[N - 1] が |0> であることを条件にして、再帰的に WState_Arbitrary を適用
        X(qs[N - 1]);
        Controlled WState_Arbitrary([qs[N - 1]], qs[... N - 2]);
        X(qs[N - 1]);

        // ちなみに、ControlledOnInt は `Adj+Ctl` でないと使えないらしい
    }
}
```

    The desired state for N = 1
    # wave function for qubits with ids (least to most significant): 0
    ∣0❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    ∣1❭:	 1.000000 +  0.000000 i	 == 	******************** [ 1.000000 ]     --- [  0.00000 rad ]
    The actual state:
    # wave function for qubits with ids (least to most significant): 0
    ∣0❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    ∣1❭:	 1.000000 +  0.000000 i	 == 	******************** [ 1.000000 ]     --- [  0.00000 rad ]
    Test case passed
    The desired state for N = 2
    # wave function for qubits with ids (least to most significant): 0;1
    ∣0❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    ∣1❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    ∣2❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    ∣3❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    The actual state:
    # wave function for qubits with ids (least to most significant): 0;1
    ∣0❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    ∣1❭:	 0.707107 +  0.000000 i	 == 	***********          [ 0.500000 ]     --- [  0.00000 rad ]
    ∣2❭:	 0.707107 +  0.000000 i	 == 	**********           [ 0.500000 ]     --- [  0.00000 rad ]
    ∣3❭:	 0.000000 +  0.000000 i	 == 	                     [ 0.000000 ]
    Test case passed
    Testing on hidden test cases...

    Success!

```qsharp

```


# Advection-Diffusion-Reaction Model

This notebook demonstrates how to
- Define the equation you want to solve
- Setup up and initial-boundary value problem
- Choose a particular set of numerics
- Post-process the solution

$
\newcommand{\grad}{\nabla}
$

```python
%matplotlib inline
from proteus.iproteus import *
Profiling.logLevel=7
Profiling.verbose=False
```

# Defining an equation
The equation we want to solve is
\begin{equation*}
m_t + \nabla \cdot \left(\mathbf{f} - \mathbf{a} \grad u \right) + r = 0
\end{equation*}
where $u$ is the unknown solution and the coefficients have the specific  forms
\begin{align}
m(u) &= M u \\
f(u) &= \mathbf{B} u \\
a(u) &= \mathbf{A} \\
r(u) &= C u \\
\end{align}

# Proteus template equation
\begin{equation}
\mathbf{u} = \left[ u^0,u^1,\ldots,u^{nc-1} \right]
\end{equation}
\begin{equation*}
m^i_t + \nabla \cdot \left(\mathbf{f}^i - \sum_k^{nc-1} \mathbf{a}^{i,k} \nabla \phi^k(\mathbf{u}) \right) + r^i + H^i(\nabla u^i)= 0 \qquad \mbox{for } i=0,\ldots,nc-1
\end{equation*}

- $m$ is "mass"
- $\mathbf{f}$ is advection
- $\mathbf{a}$ is diffution
- $\phi$ is potential
- $H$ is Hamiltonian
- $r$ is reaction

Example: non-conservative advection
\begin{equation}
u_t + \mathbf{v} \cdot \nabla u = 0
\end{equation}

What is $m$?
What is $f$?
What is $H$?

```python
class LADR(TransportCoefficients.TC_base):
    """
    The coefficients of the linear advection-diffusion equation
    """
    def __init__(self,M,A,B,C):
        TransportCoefficients.TC_base.__init__(self,
                                               nc=1, #number of components
                                               variableNames=['u'],
                                               mass      = {0:{0:'linear'}},
                                               advection = {0:{0:'linear'}},
                                               diffusion = {0:{0:{0:'constant'}}},
                                               potential = {0:{0:'u'}},
                                               reaction  = {0:{0:'linear'}})

        self.M=M;
        self.A=A;
        self.B=B;
        self.C=C;
    def evaluate(self,t,c):
        c[('m',0)][:]         = self.M*c[('u',0)]
        c[('dm',0,0)][:]      = self.M
        c[('f',0)][...,0]     = self.B[0]*c[('u',0)]
        c[('f',0)][...,1]     = self.B[1]*c[('u',0)]
        c[('df',0,0)][...,0]  = self.B[0]
        c[('df',0,0)][...,1]  = self.B[1]
        c[('a',0,0)][...,0] = self.A[0][0]
        c[('a',0,0)][...,1] = self.A[0][1]
        c[('a',0,0)][...,2] = self.A[1][0]
        c[('a',0,0)][...,3] = self.A[1][1]
        c[('r',0)][:]         = self.C*c[('u',0)]
        c[('dr',0,0)][:]      = self.C

```

# Physics

```python
from proteus import default_p as p
#physics
p.name = "ladr_2d"
p.nd = 2; #Two dimensions
p.L=(1.0,1.0);
p.T=1.0

p.coefficients=LADR(M=1.0,
                    A=[[1.001,0.0],
                       [0.0,1.001]],
                    B=[0.0,0.0],
                    C=0.0)

def getDBC(x,flag):
    if x[0] == 0.0 or x[1] == 0.0:
        return lambda x,t: 1.0
    elif x[0] == p.L[0] or x[1] == p.L[1]:
        return lambda x,t: 0.0
    else:
        return None

p.dirichletConditions = {0:getDBC}
p.advectiveFluxBoundaryConditions = {}
p.diffusiveFluxBoundaryConditions = {0:{}}
p.periodicDirichletConditions = None
class IC:
    def __init__(self):
        pass
    def uOfXT(self,x,t):
        if x[0] <= 0.0 or x[1] <= 0.0:
            return 1.0
        else:
            return 0.0

p.initialConditions  = {0:IC()}
```

# Numerics

```python
from proteus import default_n as n
import proteus as pr
n.timeIntegration = pr.TimeIntegration.BackwardEuler_cfl
n.stepController = pr.StepControl.Min_dt_cfl_controller
n.runCFL=1.0
n.femSpaces = {0:pr.FemTools.C0_AffineLinearOnSimplexWithNodalBasis}
n.elementQuadrature = pr.Quadrature.SimplexGaussQuadrature(p.nd,3)
n.elementBoundaryQuadrature = pr.Quadrature.SimplexGaussQuadrature(p.nd-1,3)
n.subgridError = pr.SubgridError.AdvectionDiffusionReaction_ASGS(p.coefficients,
                                                                 p.nd,lag=False)
n.shockCapturing = pr.ShockCapturing.ResGradQuad_SC(p.coefficients,
                                                    p.nd,
                                                    shockCapturingFactor=0.99,
                                                    lag=True)
n.numericalFluxType = pr.NumericalFlux.Advection_DiagonalUpwind_Diffusion_SIPG_exterior
n.nnx=41; n.nny=41
n.tnList=[float(i)/40.0 for i in range(11)]
n.matrix = pr.LinearAlgebraTools.SparseMatrix
n.multilevelLinearSolver = pr.LinearSolvers.KSP_petsc4py
n.l_atol_res = 1.0e-8
n.parallelPartitioningType = pr.MeshTools.MeshParallelPartitioningTypes.element
n.nLayersOfOverlapForParallel = 1
n.periodicDirichletConditions = None
```

# Operator Splitting

```python
from proteus import default_s,default_so
so = default_so
so.name = p.name
so.sList=[default_s]
so.tnList = n.tnList
#so.systemStepControllerType = SplitOperator.Sequential_FixedStep
so.systemStepControllerType = SplitOperator.Sequential_FixedStep_Simple
so.systemStepExact= False
so.dt_system_fixed= 0.01
```

# Initialize Numerical Solution Object

```python
ns = NumericalSolution.NS_base(so,[p],[n],so.sList,opts)
```

# Calculate Solution

```python
failed = ns.calculateSolution('ladr_run1')
assert(not failed)
```

```python
import pylab
x = ns.modelList[0].levelModelList[-1].mesh.nodeArray[:,0]
y = ns.modelList[0].levelModelList[-1].mesh.nodeArray[:,1]
triangles = ns.modelList[0].levelModelList[-1].mesh.elementNodesArray
u = ns.modelList[0].levelModelList[-1].u[0].dof
pylab.set_cmap('plasma')
pylab.tricontourf(x,y,triangles,u)
pylab.show()
```

You can view the log like this:

```python
!cat proteus.log
```

    [       7] Initializing NumericalSolution for ladr_2d
     System includes:
    ladr_2d

    [       7] Setting Archiver(s)
    [       7] Setting up MultilevelMesh
    [       7] Building one multilevel mesh for all models
    [       7] Generating mesh for ladr_2d
    [       7] Building 41 x 41 rectangular mesh for ladr_2d
    [       7] Partitioning mesh among 1 processors using partitioningType = 0
    [       7] Number of Subdomain Elements Owned= 3200
    [       7] Number of Subdomain Elements = 3200
    [       7] Number of Subdomain Nodes Owned= 1681
    [       7] Number of Subdomain Nodes = 1681
    [       7] Number of Subdomain elementBoundaries Owned= 4880
    [       7] Number of Subdomain elementBoundaries = 4880
    [       7] Number of Subdomain Edges Owned= 4880
    [       7] Number of Subdomain Edges = 4880
    [       7] Finished partitioning
    [       7] *** Global ***
    Number of triangles  : 3200
    Number of edges : 4880
    Number of nodes : 1681

    *** Local ***
    Number of triangles  : 3200
    Number of edges : 4880
    Number of nodes : 1681

    [       7] Numerical Solution Sparse diffusion information key (0, 0) = (array([0, 2, 4], dtype=int32), array([0, 1, 0, 1], dtype=int32))
    [       7] Setting up MultilevelTransport for ladr_2d
    [       7] Building Transport for each mesh
    [       7] Generating Trial Space
    [       7] Generating Test Space
    [       7] Allocating u
    [       7] Allocating phi
    [       7] Setting Boundary Conditions
    [       7] Setting Boundary Conditions-1
    [       7] Setting Boundary Conditions-2
    [       7] Setting Boundary Conditions-2a
    [       7] Setting Boundary Conditions-3
    [       7] Setting Boundary Conditions-4
    [       7] Initializing OneLevelTransport
    [       7] Sparse diffusion information key (0, 0) = (array([0, 2, 4], dtype=int32), array([0, 1, 0, 1], dtype=int32))
    [       7] Shallow copy of trial shape is being used for test shape w
    [       7] Shallow copy of trial shape is being used for test shape grad(w)
    [       7] Shallow copy of trial shape is being used for test shape Hess(w)
    [       7] Shallow copy of trial shape is being used for test shape w
    [       7] Updating local to global mappings
    [       7] Building time integration object
    [       7] Calculating numerical quadrature formulas
    [       7] Element Quadrature
    [       7] Element Boundary Quadrature
    [       7] Global Exterior Element Boundary Quadrature
    [       7] Allocating residual and solution vectors
    [       7] Allocating Jacobian
    [       7] Building sparse matrix structure
    [       7] Allocating parallel storage
    [       7] Allocating ghosted parallel vectors on rank 0
    [       7] Allocating un-ghosted parallel vectors on rank 0
    [       7] Allocating matrix on rank 0
    [       7] ParMat_petsc4py comm.rank= 0 blockSize = 1 par_n= 1681 par_N=1681 par_nghost=0 par_jacobian.getSizes()= ((1681, 1681), (1681, 1681))
    [       7] Building Mesh Transfers
    [       7] Setting ladr_2d stepController to proteus.StepControl.Min_dt_cfl_controller
    [       7] Setting up MultilevelLinearSolver forladr_2d
    [       7] multilevelLinearSolverChooser type= proteus.LinearSolvers.KSP_petsc4py
    [       7] KSP atol 1.000000e-08 rtol 1.000000e-03
    [       7] Setting up MultilevelNonLinearSolver for ladr_2d
    [       7] Finished setting up models and solvers
    [       7] Setting up SimTools for ladr_2d
    [       7] Using tnList from so = ladr_2d
    [       7] Time sequence[0.0, 0.025, 0.05, 0.075, 0.1, 0.125, 0.15, 0.175, 0.2, 0.225, 0.25]
    [       7] NAHeader Num Time Steps 10
    [       7] Setting ladr_2d systemStepController to object of type proteus.SplitOperator.Sequential_tnList
    [       7] Finished NumericalSolution initialization
    [      10] Setting initial conditions
    [      10] Setting initial conditions for ladr_2d
    [      10] Setting initial conditions on model ladr_2d
    [      10] Attaching models and running spin-up step if requested
    [      10] Attaching models to model ladr_2d
    [      10] Attaching models to model ladr_2d
    [      10] Archiving initial conditions
    [      10] Writing initial mesh for  model = ladr_2d
    [      10] Writing initial conditions for  model = ladr_2d
    [      10] Syncing Archive
    [      10] Gathering Archive Time step
    [      10] Done Gathering Archive Time Step
    [      10] Done Syncing Archive
    [      10] Estimating initial time derivative and initializing time history for model ladr_2d
    [      10] Choosing initial time step for model ladr_2d
    [      10] Initializing time step on model ladr_2d to dt =  2.23607e-02
    [      10] Initializing time history for model step controller
    [      10] Initializing time step on system Default System to dt =  2.50000e-02
    [      10] Initializing step sequence  for system Default System to [(0.025, <proteus.Transport.MultilevelTransport instance at 0x7f9c83239d40>)]
    [      10] Auxiliary variable calculations for model ladr_2d
    [      10] Starting time stepping
    [      10] ==============================================================
    [      10] Solving over interval [ 0.00000e+00, 2.50000e-02]
    [      10] ==============================================================
    [      10] System time step t= 2.50000e-02, dt= 2.50000e-02
    [      10] Split operator iteration 0
    [      10] NumericalAnalytics Model ladr_2d
    [      10] Model: ladr_2d
    [      10] NumericalAnalytics Time Step 0.025
    [      10] Fractional step  2.50000e-02 for model ladr_2d
    [      10] Step exact called for model ladr_2d
    [      10] StepControl base stepExact t_model= 0.025 tOut= 0.025 t_model_last= 0.0 dt_model= 0.025 setting to 0.025
    [      10] Min_dt_controller setSubsteps tList=[0.025] self.t_model=0.025 self.substeps= [0.025]
    [      10] Model step t= 2.50000e-02, dt= 2.50000e-02 for model ladr_2d
    [      10] Model substep t= 2.50000e-02 for model ladr_2d
    [      10] Model substep t= 2.50000e-02 for model ladr_2d model.timeIntegration.t=  2.50000e-02
    [      10]   NumericalAnalytics NewtonIteration: 0, NewtonNorm:  5.29005e+00
    [      10]    Newton it 0 norm(r) =  5.29005e+00  		 norm(r)/(rtol*norm(r0)+atol) = 5.02426 test=r
    [      10] before ksp.rtol= 0.001 ksp.atol= 1e-08 ksp.converged= False ksp.its= 0 ksp.norm= 0.0
    [      10] NumericalAnalytics KSPOuterResidual:  5.29005e+00
    [      10] NumericalAnalytics KSPOuterResidual(relative):  1.00000e+00
    [      10]         KSP it 0 norm(r) = 5.290050e+00  norm(r)/|b| = 1.000000e+00 ; atol=1.000000e-08 rtol=1.000000e-03
    [      10] NumericalAnalytics KSPOuterResidual:  7.11089e-02
    [      10] NumericalAnalytics KSPOuterResidual(relative):  1.34420e-02
    [      10]         KSP it 1 norm(r) = 7.110889e-02  norm(r)/|b| = 1.344201e-02 ; atol=1.000000e-08 rtol=1.000000e-03
    [      10] NumericalAnalytics KSPOuterResidual:  2.66022e-03
    [      10] NumericalAnalytics KSPOuterResidual(relative):  5.02873e-04
    [      10]         KSP it 2 norm(r) = 2.660224e-03  norm(r)/|b| = 5.028732e-04 ; atol=1.000000e-08 rtol=1.000000e-03
    [      10] after ksp.rtol= 0.001 ksp.atol= 1e-08 ksp.converged= True ksp.its= 2 ksp.norm= 0.0172731492601 reason = 2
    [      10]   NumericalAnalytics NewtonIteration: 0, NewtonNorm:  2.66022e-03
    [      10]    Newton it 1 norm(r) =  2.66022e-03  		 norm(r)/(rtol*norm(r0)+atol) =  2.52657e-03
    [      10] SO_base modelStepTaken for model= ladr_2d t_system_last= 0.0 t_model_last= 0.0  setting to t_stepSequence= 0.025
    [      10] Step Taken, t_stepSequence= 0.025 Model step t= 2.50000e-02, dt= 2.50000e-02 for model ladr_2d
    [      10] Step Taken, Model step t= 2.50000e-02, dt= 2.50000e-02 for model ladr_2d
    [      10] Min_dt_controller setSubsteps tList=[0.047360679774997805] self.t_model=0.047360679775 self.substeps= [0.047360679774997805]
    [      10] Step Taken, System time step t= 2.50000e-02, dt= 2.50000e-02
    [      10] Potential System time step t= 5.00000e-02, dt= 2.50000e-02 for next step
    [      10] Writing mesh header for  model = ladr_2d at time t=0.025
    [      10] Writing solution for  model = ladr_2d
    [      10] Syncing Archive
    [      10] Gathering Archive Time step
    [      10] Done Gathering Archive Time Step
    [      10] Done Syncing Archive
    [      10] ==============================================================
    [      10] Solving over interval [ 2.50000e-02, 5.00000e-02]
    [      10] ==============================================================
    [      10] System time step t= 5.00000e-02, dt= 2.50000e-02
    [      10] Split operator iteration 0
    [      10] NumericalAnalytics Model ladr_2d
    [      10] Model: ladr_2d
    [      10] NumericalAnalytics Time Step 0.05
    [      10] Fractional step  5.00000e-02 for model ladr_2d
    [      10] Step exact called for model ladr_2d
    [      10] StepControl base stepExact t_model= 0.05 tOut= 0.05 t_model_last= 0.025 dt_model= 0.025 setting to 0.025
    [      10] Min_dt_controller setSubsteps tList=[0.05] self.t_model=0.05 self.substeps= [0.05]
    [      10] Model step t= 5.00000e-02, dt= 2.50000e-02 for model ladr_2d
    [      10] Model substep t= 5.00000e-02 for model ladr_2d
    [      10] Model substep t= 5.00000e-02 for model ladr_2d model.timeIntegration.t=  5.00000e-02
    [      10]   NumericalAnalytics NewtonIteration: 0, NewtonNorm:  1.77029e-01
    [      10]    Newton it 0 norm(r) =  1.77029e-01  		 norm(r)/(rtol*norm(r0)+atol) = 0.176716 test=r
    [      10] before ksp.rtol= 0.001 ksp.atol= 1e-08 ksp.converged= False ksp.its= 2 ksp.norm= 0.0172731492601
    [      10] NumericalAnalytics KSPOuterResidual:  1.77029e-01
    [      10] NumericalAnalytics KSPOuterResidual(relative):  1.00000e+00
    [      10]         KSP it 0 norm(r) = 1.770289e-01  norm(r)/|b| = 1.000000e+00 ; atol=1.000000e-08 rtol=1.000000e-03
    [      10] NumericalAnalytics KSPOuterResidual:  7.50589e-03
    [      10] NumericalAnalytics KSPOuterResidual(relative):  4.23992e-02
    [      10]         KSP it 1 norm(r) = 7.505885e-03  norm(r)/|b| = 4.239920e-02 ; atol=1.000000e-08 rtol=1.000000e-03
    [      10] NumericalAnalytics KSPOuterResidual:  2.03490e-04
    [      10] NumericalAnalytics KSPOuterResidual(relative):  1.14948e-03
    [      10]         KSP it 2 norm(r) = 2.034904e-04  norm(r)/|b| = 1.149475e-03 ; atol=1.000000e-08 rtol=1.000000e-03
    [      10] NumericalAnalytics KSPOuterResidual:  2.41135e-05
    [      10] NumericalAnalytics KSPOuterResidual(relative):  1.36212e-04
    [      10]         KSP it 3 norm(r) = 2.411352e-05  norm(r)/|b| = 1.362123e-04 ; atol=1.000000e-08 rtol=1.000000e-03
    [      10] after ksp.rtol= 0.001 ksp.atol= 1e-08 ksp.converged= True ksp.its= 3 ksp.norm= 0.00025068318313 reason = 2
    [      10]   NumericalAnalytics NewtonIteration: 0, NewtonNorm:  2.41135e-05
    [      10]    Newton it 1 norm(r) =  2.41135e-05  		 norm(r)/(rtol*norm(r0)+atol) =  2.40709e-05
    [      10] SO_base modelStepTaken for model= ladr_2d t_system_last= 0.025 t_model_last= 0.025  setting to t_stepSequence= 0.05
    [      10] Step Taken, t_stepSequence= 0.05 Model step t= 5.00000e-02, dt= 2.50000e-02 for model ladr_2d
    [      10] Step Taken, Model step t= 5.00000e-02, dt= 2.50000e-02 for model ladr_2d
    [      10] Min_dt_controller setSubsteps tList=[0.0723606797749978] self.t_model=0.072360679775 self.substeps= [0.0723606797749978]
    [      10] Step Taken, System time step t= 5.00000e-02, dt= 2.50000e-02
    [      10] Potential System time step t= 7.50000e-02, dt= 2.50000e-02 for next step
    [      10] Writing mesh header for  model = ladr_2d at time t=0.05
    [      10] Writing solution for  model = ladr_2d
    [      10] Syncing Archive
    [      10] Gathering Archive Time step
    [      10] Done Gathering Archive Time Step
    [      10] Done Syncing Archive
    [      10] ==============================================================
    [      10] Solving over interval [ 5.00000e-02, 7.50000e-02]
    [      10] ==============================================================
    [      10] System time step t= 7.50000e-02, dt= 2.50000e-02
    [      10] Split operator iteration 0
    [      10] NumericalAnalytics Model ladr_2d
    [      10] Model: ladr_2d
    [      10] NumericalAnalytics Time Step 0.07500000000000001
    [      10] Fractional step  7.50000e-02 for model ladr_2d
    [      10] Step exact called for model ladr_2d
    [      10] StepControl base stepExact t_model= 0.075 tOut= 0.075 t_model_last= 0.05 dt_model= 0.025 setting to 0.025
    [      10] Min_dt_controller setSubsteps tList=[0.07500000000000001] self.t_model=0.075 self.substeps= [0.07500000000000001]
    [      10] Model step t= 7.50000e-02, dt= 2.50000e-02 for model ladr_2d
    [      10] Model substep t= 7.50000e-02 for model ladr_2d
    [      10] Model substep t= 7.50000e-02 for model ladr_2d model.timeIntegration.t=  7.50000e-02
    [      10]   NumericalAnalytics NewtonIteration: 0, NewtonNorm:  1.24891e-01
    [      10]    Newton it 0 norm(r) =  1.24891e-01  		 norm(r)/(rtol*norm(r0)+atol) = 0.124735 test=r
    [      10] before ksp.rtol= 0.001 ksp.atol= 1e-08 ksp.converged= False ksp.its= 3 ksp.norm= 0.00025068318313
    [      10] NumericalAnalytics KSPOuterResidual:  1.24891e-01
    [      10] NumericalAnalytics KSPOuterResidual(relative):  1.00000e+00
    [      10]         KSP it 0 norm(r) = 1.248906e-01  norm(r)/|b| = 1.000000e+00 ; atol=1.000000e-08 rtol=1.000000e-03
    [      10] NumericalAnalytics KSPOuterResidual:  4.79993e-03
    [      10] NumericalAnalytics KSPOuterResidual(relative):  3.84331e-02
    [      10]         KSP it 1 norm(r) = 4.799934e-03  norm(r)/|b| = 3.843310e-02 ; atol=1.000000e-08 rtol=1.000000e-03
    [      10] NumericalAnalytics KSPOuterResidual:  2.02059e-04
    [      10] NumericalAnalytics KSPOuterResidual(relative):  1.61789e-03
    [      10]         KSP it 2 norm(r) = 2.020589e-04  norm(r)/|b| = 1.617887e-03 ; atol=1.000000e-08 rtol=1.000000e-03
    [      10] NumericalAnalytics KSPOuterResidual:  7.41354e-06
    [      10] NumericalAnalytics KSPOuterResidual(relative):  5.93602e-05
    [      10]         KSP it 3 norm(r) = 7.413537e-06  norm(r)/|b| = 5.936024e-05 ; atol=1.000000e-08 rtol=1.000000e-03
    [      10] after ksp.rtol= 0.001 ksp.atol= 1e-08 ksp.converged= True ksp.its= 3 ksp.norm= 0.000133905663706 reason = 2
    [      10]   NumericalAnalytics NewtonIteration: 0, NewtonNorm:  7.41354e-06
    [      10]    Newton it 1 norm(r) =  7.41354e-06  		 norm(r)/(rtol*norm(r0)+atol) =  7.40429e-06
    [      10] SO_base modelStepTaken for model= ladr_2d t_system_last= 0.05 t_model_last= 0.05  setting to t_stepSequence= 0.075
    [      10] Step Taken, t_stepSequence= 0.075 Model step t= 7.50000e-02, dt= 2.50000e-02 for model ladr_2d
    [      10] Step Taken, Model step t= 7.50000e-02, dt= 2.50000e-02 for model ladr_2d
    [      10] Min_dt_controller setSubsteps tList=[0.09736067977499781] self.t_model=0.097360679775 self.substeps= [0.09736067977499781]
    [      10] Step Taken, System time step t= 7.50000e-02, dt= 2.50000e-02
    [      10] Potential System time step t= 1.00000e-01, dt= 2.50000e-02 for next step
    [      10] Writing mesh header for  model = ladr_2d at time t=0.075
    [      10] Writing solution for  model = ladr_2d
    [      10] Syncing Archive
    [      10] Gathering Archive Time step
    [      10] Done Gathering Archive Time Step
    [      10] Done Syncing Archive
    [      10] ==============================================================
    [      10] Solving over interval [ 7.50000e-02, 1.00000e-01]
    [      10] ==============================================================
    [      10] System time step t= 1.00000e-01, dt= 2.50000e-02
    [      10] Split operator iteration 0
    [      10] NumericalAnalytics Model ladr_2d
    [      10] Model: ladr_2d
    [      10] NumericalAnalytics Time Step 0.1
    [      10] Fractional step  1.00000e-01 for model ladr_2d
    [      10] Step exact called for model ladr_2d
    [      10] StepControl base stepExact t_model= 0.1 tOut= 0.1 t_model_last= 0.075 dt_model= 0.025 setting to 0.025
    [      10] Min_dt_controller setSubsteps tList=[0.1] self.t_model=0.1 self.substeps= [0.1]
    [      10] Model step t= 1.00000e-01, dt= 2.50000e-02 for model ladr_2d
    [      10] Model substep t= 1.00000e-01 for model ladr_2d
    [      10] Model substep t= 1.00000e-01 for model ladr_2d model.timeIntegration.t=  1.00000e-01
    [      10]   NumericalAnalytics NewtonIteration: 0, NewtonNorm:  1.06896e-01
    [      10]    Newton it 0 norm(r) =  1.06896e-01  		 norm(r)/(rtol*norm(r0)+atol) = 0.106782 test=r
    [      10] before ksp.rtol= 0.001 ksp.atol= 1e-08 ksp.converged= False ksp.its= 3 ksp.norm= 0.000133905663706
    [      10] NumericalAnalytics KSPOuterResidual:  1.06896e-01
    [      10] NumericalAnalytics KSPOuterResidual(relative):  1.00000e+00
    [      10]         KSP it 0 norm(r) = 1.068960e-01  norm(r)/|b| = 1.000000e+00 ; atol=1.000000e-08 rtol=1.000000e-03
    [      10] NumericalAnalytics KSPOuterResidual:  4.59059e-03
    [      10] NumericalAnalytics KSPOuterResidual(relative):  4.29445e-02
    [      10]         KSP it 1 norm(r) = 4.590594e-03  norm(r)/|b| = 4.294450e-02 ; atol=1.000000e-08 rtol=1.000000e-03
    [      10] NumericalAnalytics KSPOuterResidual:  2.58342e-04
    [      10] NumericalAnalytics KSPOuterResidual(relative):  2.41676e-03
    [      10]         KSP it 2 norm(r) = 2.583418e-04  norm(r)/|b| = 2.416759e-03 ; atol=1.000000e-08 rtol=1.000000e-03
    [      10] NumericalAnalytics KSPOuterResidual:  1.26881e-05
    [      10] NumericalAnalytics KSPOuterResidual(relative):  1.18695e-04
    [      10]         KSP it 3 norm(r) = 1.268806e-05  norm(r)/|b| = 1.186954e-04 ; atol=1.000000e-08 rtol=1.000000e-03
    [      10] after ksp.rtol= 0.001 ksp.atol= 1e-08 ksp.converged= True ksp.its= 3 ksp.norm= 0.000278368747315 reason = 2
    [      10]   NumericalAnalytics NewtonIteration: 0, NewtonNorm:  1.26881e-05
    [      10]    Newton it 1 norm(r) =  1.26881e-05  		 norm(r)/(rtol*norm(r0)+atol) =  1.26745e-05
    [      10] SO_base modelStepTaken for model= ladr_2d t_system_last= 0.075 t_model_last= 0.075  setting to t_stepSequence= 0.1
    [      10] Step Taken, t_stepSequence= 0.1 Model step t= 1.00000e-01, dt= 2.50000e-02 for model ladr_2d
    [      10] Step Taken, Model step t= 1.00000e-01, dt= 2.50000e-02 for model ladr_2d
    [      10] Min_dt_controller setSubsteps tList=[0.1223606797749978] self.t_model=0.122360679775 self.substeps= [0.1223606797749978]
    [      10] Step Taken, System time step t= 1.00000e-01, dt= 2.50000e-02
    [      10] Potential System time step t= 1.25000e-01, dt= 2.50000e-02 for next step
    [      10] Writing mesh header for  model = ladr_2d at time t=0.1
    [      10] Writing solution for  model = ladr_2d
    [      10] Syncing Archive
    [      10] Gathering Archive Time step
    [      10] Done Gathering Archive Time Step
    [      10] Done Syncing Archive
    [      10] ==============================================================
    [      10] Solving over interval [ 1.00000e-01, 1.25000e-01]
    [      10] ==============================================================
    [      10] System time step t= 1.25000e-01, dt= 2.50000e-02
    [      10] Split operator iteration 0
    [      10] NumericalAnalytics Model ladr_2d
    [      10] Model: ladr_2d
    [      10] NumericalAnalytics Time Step 0.125
    [      10] Fractional step  1.25000e-01 for model ladr_2d
    [      10] Step exact called for model ladr_2d
    [      10] StepControl base stepExact t_model= 0.125 tOut= 0.125 t_model_last= 0.1 dt_model= 0.025 setting to 0.025
    [      10] Min_dt_controller setSubsteps tList=[0.125] self.t_model=0.125 self.substeps= [0.125]
    [      10] Model step t= 1.25000e-01, dt= 2.50000e-02 for model ladr_2d
    [      10] Model substep t= 1.25000e-01 for model ladr_2d
    [      10] Model substep t= 1.25000e-01 for model ladr_2d model.timeIntegration.t=  1.25000e-01
    [      10]   NumericalAnalytics NewtonIteration: 0, NewtonNorm:  9.59865e-02
    [      10]    Newton it 0 norm(r) =  9.59865e-02  		 norm(r)/(rtol*norm(r0)+atol) = 0.0958944 test=r
    [      10] before ksp.rtol= 0.001 ksp.atol= 1e-08 ksp.converged= False ksp.its= 3 ksp.norm= 0.000278368747315
    [      10] NumericalAnalytics KSPOuterResidual:  9.59865e-02
    [      10] NumericalAnalytics KSPOuterResidual(relative):  1.00000e+00
    [      10]         KSP it 0 norm(r) = 9.598646e-02  norm(r)/|b| = 1.000000e+00 ; atol=1.000000e-08 rtol=1.000000e-03
    [      10] NumericalAnalytics KSPOuterResidual:  4.33206e-03
    [      10] NumericalAnalytics KSPOuterResidual(relative):  4.51320e-02
    [      10]         KSP it 1 norm(r) = 4.332063e-03  norm(r)/|b| = 4.513202e-02 ; atol=1.000000e-08 rtol=1.000000e-03
    [      10] NumericalAnalytics KSPOuterResidual:  2.88313e-04
    [      10] NumericalAnalytics KSPOuterResidual(relative):  3.00368e-03
    [      10]         KSP it 2 norm(r) = 2.883126e-04  norm(r)/|b| = 3.003680e-03 ; atol=1.000000e-08 rtol=1.000000e-03
    [      10] NumericalAnalytics KSPOuterResidual:  1.59841e-05
    [      10] NumericalAnalytics KSPOuterResidual(relative):  1.66525e-04
    [      10]         KSP it 3 norm(r) = 1.598411e-05  norm(r)/|b| = 1.665246e-04 ; atol=1.000000e-08 rtol=1.000000e-03
    [      10] after ksp.rtol= 0.001 ksp.atol= 1e-08 ksp.converged= True ksp.its= 3 ksp.norm= 0.000354836555651 reason = 2
    [      10]   NumericalAnalytics NewtonIteration: 0, NewtonNorm:  1.59841e-05
    [      10]    Newton it 1 norm(r) =  1.59841e-05  		 norm(r)/(rtol*norm(r0)+atol) =  1.59688e-05
    [      10] SO_base modelStepTaken for model= ladr_2d t_system_last= 0.1 t_model_last= 0.1  setting to t_stepSequence= 0.125
    [      10] Step Taken, t_stepSequence= 0.125 Model step t= 1.25000e-01, dt= 2.50000e-02 for model ladr_2d
    [      10] Step Taken, Model step t= 1.25000e-01, dt= 2.50000e-02 for model ladr_2d
    [      10] Min_dt_controller setSubsteps tList=[0.1473606797749978] self.t_model=0.147360679775 self.substeps= [0.1473606797749978]
    [      10] Step Taken, System time step t= 1.25000e-01, dt= 2.50000e-02
    [      10] Potential System time step t= 1.50000e-01, dt= 2.50000e-02 for next step
    [      10] Writing mesh header for  model = ladr_2d at time t=0.125
    [      10] Writing solution for  model = ladr_2d
    [      10] Syncing Archive
    [      10] Gathering Archive Time step
    [      10] Done Gathering Archive Time Step
    [      10] Done Syncing Archive
    [      10] ==============================================================
    [      10] Solving over interval [ 1.25000e-01, 1.50000e-01]
    [      10] ==============================================================
    [      10] System time step t= 1.50000e-01, dt= 2.50000e-02
    [      10] Split operator iteration 0
    [      10] NumericalAnalytics Model ladr_2d
    [      10] Model: ladr_2d
    [      10] NumericalAnalytics Time Step 0.15
    [      10] Fractional step  1.50000e-01 for model ladr_2d
    [      10] Step exact called for model ladr_2d
    [      10] StepControl base stepExact t_model= 0.15 tOut= 0.15 t_model_last= 0.125 dt_model= 0.025 setting to 0.025
    [      10] Min_dt_controller setSubsteps tList=[0.15] self.t_model=0.15 self.substeps= [0.15]
    [      10] Model step t= 1.50000e-01, dt= 2.50000e-02 for model ladr_2d
    [      10] Model substep t= 1.50000e-01 for model ladr_2d
    [      10] Model substep t= 1.50000e-01 for model ladr_2d model.timeIntegration.t=  1.50000e-01
    [      10]   NumericalAnalytics NewtonIteration: 0, NewtonNorm:  8.80686e-02
    [      10]    Newton it 0 norm(r) =  8.80686e-02  		 norm(r)/(rtol*norm(r0)+atol) = 0.0879911 test=r
    [      10] before ksp.rtol= 0.001 ksp.atol= 1e-08 ksp.converged= False ksp.its= 3 ksp.norm= 0.000354836555651
    [      10] NumericalAnalytics KSPOuterResidual:  8.80686e-02
    [      10] NumericalAnalytics KSPOuterResidual(relative):  1.00000e+00
    [      10]         KSP it 0 norm(r) = 8.806862e-02  norm(r)/|b| = 1.000000e+00 ; atol=1.000000e-08 rtol=1.000000e-03
    [      10] NumericalAnalytics KSPOuterResidual:  4.10486e-03
    [      10] NumericalAnalytics KSPOuterResidual(relative):  4.66098e-02
    [      10]         KSP it 1 norm(r) = 4.104861e-03  norm(r)/|b| = 4.660980e-02 ; atol=1.000000e-08 rtol=1.000000e-03
    [      10] NumericalAnalytics KSPOuterResidual:  3.05850e-04
    [      10] NumericalAnalytics KSPOuterResidual(relative):  3.47286e-03
    [      10]         KSP it 2 norm(r) = 3.058504e-04  norm(r)/|b| = 3.472865e-03 ; atol=1.000000e-08 rtol=1.000000e-03
    [      10] NumericalAnalytics KSPOuterResidual:  1.88417e-05
    [      10] NumericalAnalytics KSPOuterResidual(relative):  2.13943e-04
    [      10]         KSP it 3 norm(r) = 1.884168e-05  norm(r)/|b| = 2.139432e-04 ; atol=1.000000e-08 rtol=1.000000e-03
    [      10] after ksp.rtol= 0.001 ksp.atol= 1e-08 ksp.converged= True ksp.its= 3 ksp.norm= 0.000385940949573 reason = 2
    [      10]   NumericalAnalytics NewtonIteration: 0, NewtonNorm:  1.88417e-05
    [      10]    Newton it 1 norm(r) =  1.88417e-05  		 norm(r)/(rtol*norm(r0)+atol) =  1.88251e-05
    [      10] SO_base modelStepTaken for model= ladr_2d t_system_last= 0.125 t_model_last= 0.125  setting to t_stepSequence= 0.15
    [      10] Step Taken, t_stepSequence= 0.15 Model step t= 1.50000e-01, dt= 2.50000e-02 for model ladr_2d
    [      10] Step Taken, Model step t= 1.50000e-01, dt= 2.50000e-02 for model ladr_2d
    [      10] Min_dt_controller setSubsteps tList=[0.1723606797749978] self.t_model=0.172360679775 self.substeps= [0.1723606797749978]
    [      10] Step Taken, System time step t= 1.50000e-01, dt= 2.50000e-02
    [      10] Potential System time step t= 1.75000e-01, dt= 2.50000e-02 for next step
    [      10] Writing mesh header for  model = ladr_2d at time t=0.15
    [      10] Writing solution for  model = ladr_2d
    [      10] Syncing Archive
    [      10] Gathering Archive Time step
    [      10] Done Gathering Archive Time Step
    [      10] Done Syncing Archive
    [      10] ==============================================================
    [      10] Solving over interval [ 1.50000e-01, 1.75000e-01]
    [      10] ==============================================================
    [      10] System time step t= 1.75000e-01, dt= 2.50000e-02
    [      10] Split operator iteration 0
    [      10] NumericalAnalytics Model ladr_2d
    [      10] Model: ladr_2d
    [      10] NumericalAnalytics Time Step 0.175
    [      10] Fractional step  1.75000e-01 for model ladr_2d
    [      10] Step exact called for model ladr_2d
    [      10] StepControl base stepExact t_model= 0.175 tOut= 0.175 t_model_last= 0.15 dt_model= 0.025 setting to 0.025
    [      10] Min_dt_controller setSubsteps tList=[0.175] self.t_model=0.175 self.substeps= [0.175]
    [      10] Model step t= 1.75000e-01, dt= 2.50000e-02 for model ladr_2d
    [      10] Model substep t= 1.75000e-01 for model ladr_2d
    [      10] Model substep t= 1.75000e-01 for model ladr_2d model.timeIntegration.t=  1.75000e-01
    [      10]   NumericalAnalytics NewtonIteration: 0, NewtonNorm:  8.18807e-02
    [      10]    Newton it 0 norm(r) =  8.18807e-02  		 norm(r)/(rtol*norm(r0)+atol) = 0.0818137 test=r
    [      10] before ksp.rtol= 0.001 ksp.atol= 1e-08 ksp.converged= False ksp.its= 3 ksp.norm= 0.000385940949573
    [      10] NumericalAnalytics KSPOuterResidual:  8.18807e-02
    [      10] NumericalAnalytics KSPOuterResidual(relative):  1.00000e+00
    [      10]         KSP it 0 norm(r) = 8.188069e-02  norm(r)/|b| = 1.000000e+00 ; atol=1.000000e-08 rtol=1.000000e-03
    [      10] NumericalAnalytics KSPOuterResidual:  3.96670e-03
    [      10] NumericalAnalytics KSPOuterResidual(relative):  4.84449e-02
    [      10]         KSP it 1 norm(r) = 3.966704e-03  norm(r)/|b| = 4.844492e-02 ; atol=1.000000e-08 rtol=1.000000e-03
    [      10] NumericalAnalytics KSPOuterResidual:  3.21006e-04
    [      10] NumericalAnalytics KSPOuterResidual(relative):  3.92042e-03
    [      10]         KSP it 2 norm(r) = 3.210065e-04  norm(r)/|b| = 3.920417e-03 ; atol=1.000000e-08 rtol=1.000000e-03
    [      10] NumericalAnalytics KSPOuterResidual:  2.12893e-05
    [      10] NumericalAnalytics KSPOuterResidual(relative):  2.60003e-04
    [      10]         KSP it 3 norm(r) = 2.128926e-05  norm(r)/|b| = 2.600034e-04 ; atol=1.000000e-08 rtol=1.000000e-03
    [      10] after ksp.rtol= 0.001 ksp.atol= 1e-08 ksp.converged= True ksp.its= 3 ksp.norm= 0.000413700257666 reason = 2
    [      10]   NumericalAnalytics NewtonIteration: 0, NewtonNorm:  2.12893e-05
    [      10]    Newton it 1 norm(r) =  2.12893e-05  		 norm(r)/(rtol*norm(r0)+atol) =  2.12718e-05
    [      10] SO_base modelStepTaken for model= ladr_2d t_system_last= 0.15 t_model_last= 0.15  setting to t_stepSequence= 0.175
    [      10] Step Taken, t_stepSequence= 0.175 Model step t= 1.75000e-01, dt= 2.50000e-02 for model ladr_2d
    [      10] Step Taken, Model step t= 1.75000e-01, dt= 2.50000e-02 for model ladr_2d
    [      10] Min_dt_controller setSubsteps tList=[0.1973606797749978] self.t_model=0.197360679775 self.substeps= [0.1973606797749978]
    [      10] Step Taken, System time step t= 1.75000e-01, dt= 2.50000e-02
    [      10] Potential System time step t= 2.00000e-01, dt= 2.50000e-02 for next step
    [      10] Writing mesh header for  model = ladr_2d at time t=0.175
    [      10] Writing solution for  model = ladr_2d
    [      10] Syncing Archive
    [      10] Gathering Archive Time step
    [      10] Done Gathering Archive Time Step
    [      10] Done Syncing Archive
    [      10] ==============================================================
    [      10] Solving over interval [ 1.75000e-01, 2.00000e-01]
    [      10] ==============================================================
    [      10] System time step t= 2.00000e-01, dt= 2.50000e-02
    [      10] Split operator iteration 0
    [      10] NumericalAnalytics Model ladr_2d
    [      10] Model: ladr_2d
    [      10] NumericalAnalytics Time Step 0.19999999999999998
    [      10] Fractional step  2.00000e-01 for model ladr_2d
    [      10] Step exact called for model ladr_2d
    [      10] StepControl base stepExact t_model= 0.2 tOut= 0.2 t_model_last= 0.175 dt_model= 0.025 setting to 0.025
    [      10] Min_dt_controller setSubsteps tList=[0.19999999999999998] self.t_model=0.2 self.substeps= [0.19999999999999998]
    [      10] Model step t= 2.00000e-01, dt= 2.50000e-02 for model ladr_2d
    [      10] Model substep t= 2.00000e-01 for model ladr_2d
    [      10] Model substep t= 2.00000e-01 for model ladr_2d model.timeIntegration.t=  2.00000e-01
    [      10]   NumericalAnalytics NewtonIteration: 0, NewtonNorm:  7.67485e-02
    [      10]    Newton it 0 norm(r) =  7.67485e-02  		 norm(r)/(rtol*norm(r0)+atol) = 0.0766896 test=r
    [      10] before ksp.rtol= 0.001 ksp.atol= 1e-08 ksp.converged= False ksp.its= 3 ksp.norm= 0.000413700257666
    [      10] NumericalAnalytics KSPOuterResidual:  7.67485e-02
    [      10] NumericalAnalytics KSPOuterResidual(relative):  1.00000e+00
    [      10]         KSP it 0 norm(r) = 7.674849e-02  norm(r)/|b| = 1.000000e+00 ; atol=1.000000e-08 rtol=1.000000e-03
    [      10] NumericalAnalytics KSPOuterResidual:  3.87360e-03
    [      10] NumericalAnalytics KSPOuterResidual(relative):  5.04713e-02
    [      10]         KSP it 1 norm(r) = 3.873599e-03  norm(r)/|b| = 5.047134e-02 ; atol=1.000000e-08 rtol=1.000000e-03
    [      10] NumericalAnalytics KSPOuterResidual:  3.30223e-04
    [      10] NumericalAnalytics KSPOuterResidual(relative):  4.30266e-03
    [      10]         KSP it 2 norm(r) = 3.302227e-04  norm(r)/|b| = 4.302660e-03 ; atol=1.000000e-08 rtol=1.000000e-03
    [      10] NumericalAnalytics KSPOuterResidual:  2.31376e-05
    [      10] NumericalAnalytics KSPOuterResidual(relative):  3.01473e-04
    [      10]         KSP it 3 norm(r) = 2.313760e-05  norm(r)/|b| = 3.014731e-04 ; atol=1.000000e-08 rtol=1.000000e-03
    [      10] after ksp.rtol= 0.001 ksp.atol= 1e-08 ksp.converged= True ksp.its= 3 ksp.norm= 0.000439317938712 reason = 2
    [      10]   NumericalAnalytics NewtonIteration: 0, NewtonNorm:  2.31376e-05
    [      10]    Newton it 1 norm(r) =  2.31376e-05  		 norm(r)/(rtol*norm(r0)+atol) =  2.31199e-05
    [      10] SO_base modelStepTaken for model= ladr_2d t_system_last= 0.175 t_model_last= 0.175  setting to t_stepSequence= 0.2
    [      10] Step Taken, t_stepSequence= 0.2 Model step t= 2.00000e-01, dt= 2.50000e-02 for model ladr_2d
    [      10] Step Taken, Model step t= 2.00000e-01, dt= 2.50000e-02 for model ladr_2d
    [      10] Min_dt_controller setSubsteps tList=[0.2223606797749978] self.t_model=0.222360679775 self.substeps= [0.2223606797749978]
    [      10] Step Taken, System time step t= 2.00000e-01, dt= 2.50000e-02
    [      10] Potential System time step t= 2.25000e-01, dt= 2.50000e-02 for next step
    [      10] System time step t= 2.25000e-01, dt= 2.50000e-02
    [      10] Split operator iteration 0
    [      10] NumericalAnalytics Model ladr_2d
    [      10] Model: ladr_2d
    [      10] NumericalAnalytics Time Step 0.22499999999999998
    [      10] Fractional step  2.25000e-01 for model ladr_2d
    [      10] Step exact called for model ladr_2d
    [      10] StepControl base stepExact t_model= 0.225 tOut= 0.225 t_model_last= 0.2 dt_model= 0.025 setting to 0.025
    [      10] Min_dt_controller setSubsteps tList=[0.22499999999999998] self.t_model=0.225 self.substeps= [0.22499999999999998]
    [      10] Model step t= 2.25000e-01, dt= 2.50000e-02 for model ladr_2d
    [      10] Model substep t= 2.25000e-01 for model ladr_2d
    [      10] Model substep t= 2.25000e-01 for model ladr_2d model.timeIntegration.t=  2.25000e-01
    [      10]   NumericalAnalytics NewtonIteration: 0, NewtonNorm:  7.23193e-02
    [      10]    Newton it 0 norm(r) =  7.23193e-02  		 norm(r)/(rtol*norm(r0)+atol) = 0.072267 test=r
    [      10] before ksp.rtol= 0.001 ksp.atol= 1e-08 ksp.converged= False ksp.its= 3 ksp.norm= 0.000439317938712
    [      10] NumericalAnalytics KSPOuterResidual:  7.23193e-02
    [      10] NumericalAnalytics KSPOuterResidual(relative):  1.00000e+00
    [      10]         KSP it 0 norm(r) = 7.231931e-02  norm(r)/|b| = 1.000000e+00 ; atol=1.000000e-08 rtol=1.000000e-03
    [      10] NumericalAnalytics KSPOuterResidual:  3.80043e-03
    [      10] NumericalAnalytics KSPOuterResidual(relative):  5.25507e-02
    [      10]         KSP it 1 norm(r) = 3.800430e-03  norm(r)/|b| = 5.255070e-02 ; atol=1.000000e-08 rtol=1.000000e-03
    [      10] NumericalAnalytics KSPOuterResidual:  3.34198e-04
    [      10] NumericalAnalytics KSPOuterResidual(relative):  4.62115e-03
    [      10]         KSP it 2 norm(r) = 3.341982e-04  norm(r)/|b| = 4.621148e-03 ; atol=1.000000e-08 rtol=1.000000e-03
    [      10] NumericalAnalytics KSPOuterResidual:  2.44725e-05
    [      10] NumericalAnalytics KSPOuterResidual(relative):  3.38395e-04
    [      10]         KSP it 3 norm(r) = 2.447249e-05  norm(r)/|b| = 3.383949e-04 ; atol=1.000000e-08 rtol=1.000000e-03
    [      10] after ksp.rtol= 0.001 ksp.atol= 1e-08 ksp.converged= True ksp.its= 3 ksp.norm= 0.000455712273346 reason = 2
    [      10]   NumericalAnalytics NewtonIteration: 0, NewtonNorm:  2.44725e-05
    [      10]    Newton it 1 norm(r) =  2.44725e-05  		 norm(r)/(rtol*norm(r0)+atol) =  2.44548e-05
    [      10] SO_base modelStepTaken for model= ladr_2d t_system_last= 0.2 t_model_last= 0.2  setting to t_stepSequence= 0.225
    [      10] Step Taken, t_stepSequence= 0.225 Model step t= 2.25000e-01, dt= 2.50000e-02 for model ladr_2d
    [      10] Step Taken, Model step t= 2.25000e-01, dt= 2.50000e-02 for model ladr_2d
    [      10] Min_dt_controller setSubsteps tList=[0.2473606797749978] self.t_model=0.247360679775 self.substeps= [0.2473606797749978]
    [      10] Step Taken, System time step t= 2.25000e-01, dt= 2.50000e-02
    [      10] Potential System time step t= 2.50000e-01, dt= 2.50000e-02 for next step
    [      10] Writing mesh header for  model = ladr_2d at time t=0.225
    [      10] Writing solution for  model = ladr_2d
    [      10] Syncing Archive
    [      10] Gathering Archive Time step
    [      10] Done Gathering Archive Time Step
    [      10] Done Syncing Archive
    [      10] ==============================================================
    [      10] Solving over interval [ 2.00000e-01, 2.25000e-01]
    [      10] ==============================================================
    [      10] System time step t= 2.50000e-01, dt= 2.50000e-02
    [      10] Split operator iteration 0
    [      10] NumericalAnalytics Model ladr_2d
    [      10] Model: ladr_2d
    [      10] NumericalAnalytics Time Step 0.24999999999999997
    [      10] Fractional step  2.50000e-01 for model ladr_2d
    [      10] Step exact called for model ladr_2d
    [      10] StepControl base stepExact t_model= 0.25 tOut= 0.25 t_model_last= 0.225 dt_model= 0.025 setting to 0.025
    [      10] Min_dt_controller setSubsteps tList=[0.24999999999999997] self.t_model=0.25 self.substeps= [0.24999999999999997]
    [      10] Model step t= 2.50000e-01, dt= 2.50000e-02 for model ladr_2d
    [      10] Model substep t= 2.50000e-01 for model ladr_2d
    [      10] Model substep t= 2.50000e-01 for model ladr_2d model.timeIntegration.t=  2.50000e-01
    [      10]   NumericalAnalytics NewtonIteration: 0, NewtonNorm:  6.83880e-02
    [      10]    Newton it 0 norm(r) =  6.83880e-02  		 norm(r)/(rtol*norm(r0)+atol) = 0.0683412 test=r
    [      10] before ksp.rtol= 0.001 ksp.atol= 1e-08 ksp.converged= False ksp.its= 3 ksp.norm= 0.000455712273346
    [      10] NumericalAnalytics KSPOuterResidual:  6.83880e-02
    [      10] NumericalAnalytics KSPOuterResidual(relative):  1.00000e+00
    [      10]         KSP it 0 norm(r) = 6.838796e-02  norm(r)/|b| = 1.000000e+00 ; atol=1.000000e-08 rtol=1.000000e-03
    [      10] NumericalAnalytics KSPOuterResidual:  3.74333e-03
    [      10] NumericalAnalytics KSPOuterResidual(relative):  5.47367e-02
    [      10]         KSP it 1 norm(r) = 3.743332e-03  norm(r)/|b| = 5.473671e-02 ; atol=1.000000e-08 rtol=1.000000e-03
    [      10] NumericalAnalytics KSPOuterResidual:  3.34561e-04
    [      10] NumericalAnalytics KSPOuterResidual(relative):  4.89210e-03
    [      10]         KSP it 2 norm(r) = 3.345610e-04  norm(r)/|b| = 4.892104e-03 ; atol=1.000000e-08 rtol=1.000000e-03
    [      10] NumericalAnalytics KSPOuterResidual:  2.54758e-05
    [      10] NumericalAnalytics KSPOuterResidual(relative):  3.72519e-04
    [      10]         KSP it 3 norm(r) = 2.547582e-05  norm(r)/|b| = 3.725191e-04 ; atol=1.000000e-08 rtol=1.000000e-03
    [      10] after ksp.rtol= 0.001 ksp.atol= 1e-08 ksp.converged= True ksp.its= 3 ksp.norm= 0.000466103292753 reason = 2
    [      10]   NumericalAnalytics NewtonIteration: 0, NewtonNorm:  2.54758e-05
    [      10]    Newton it 1 norm(r) =  2.54758e-05  		 norm(r)/(rtol*norm(r0)+atol) =  2.54584e-05
    [      10] SO_base modelStepTaken for model= ladr_2d t_system_last= 0.225 t_model_last= 0.225  setting to t_stepSequence= 0.25
    [      10] Step Taken, t_stepSequence= 0.25 Model step t= 2.50000e-01, dt= 2.50000e-02 for model ladr_2d
    [      10] Step Taken, Model step t= 2.50000e-01, dt= 2.50000e-02 for model ladr_2d
    [      10] Min_dt_controller setSubsteps tList=[0.2723606797749978] self.t_model=0.272360679775 self.substeps= [0.2723606797749978]
    [      10] Step Taken, System time step t= 2.50000e-01, dt= 2.50000e-02
    [      10] Potential System time step t= 2.75000e-01, dt= 2.50000e-02 for next step
    [      10] Writing mesh header for  model = ladr_2d at time t=0.25
    [      10] Writing solution for  model = ladr_2d
    [      10] Syncing Archive
    [      10] Gathering Archive Time step
    [      10] Done Gathering Archive Time Step
    [      10] Done Syncing Archive
    [      10] ==============================================================
    [      10] Solving over interval [ 2.25000e-01, 2.50000e-01]
    [      10] ==============================================================
    [      10] System time step t= 2.75000e-01, dt= 2.50000e-02
    [      10] Split operator iteration 0
    [      10] NumericalAnalytics Model ladr_2d
    [      10] Model: ladr_2d
    [      10] NumericalAnalytics Time Step 0.27499999999999997
    [      10] Fractional step  2.75000e-01 for model ladr_2d
    [      10] Step exact called for model ladr_2d
    [      10] StepControl base stepExact t_model= 0.275 tOut= 0.275 t_model_last= 0.25 dt_model= 0.025 setting to 0.025
    [      10] Min_dt_controller setSubsteps tList=[0.27499999999999997] self.t_model=0.275 self.substeps= [0.27499999999999997]
    [      10] Model step t= 2.75000e-01, dt= 2.50000e-02 for model ladr_2d
    [      10] Model substep t= 2.75000e-01 for model ladr_2d
    [      10] Model substep t= 2.75000e-01 for model ladr_2d model.timeIntegration.t=  2.75000e-01
    [      10]   NumericalAnalytics NewtonIteration: 0, NewtonNorm:  6.48198e-02
    [      10]    Newton it 0 norm(r) =  6.48198e-02  		 norm(r)/(rtol*norm(r0)+atol) = 0.0647778 test=r
    [      10] before ksp.rtol= 0.001 ksp.atol= 1e-08 ksp.converged= False ksp.its= 3 ksp.norm= 0.000466103292753
    [      10] NumericalAnalytics KSPOuterResidual:  6.48198e-02
    [      10] NumericalAnalytics KSPOuterResidual(relative):  1.00000e+00
    [      10]         KSP it 0 norm(r) = 6.481982e-02  norm(r)/|b| = 1.000000e+00 ; atol=1.000000e-08 rtol=1.000000e-03
    [      10] NumericalAnalytics KSPOuterResidual:  3.70093e-03
    [      10] NumericalAnalytics KSPOuterResidual(relative):  5.70957e-02
    [      10]         KSP it 1 norm(r) = 3.700930e-03  norm(r)/|b| = 5.709565e-02 ; atol=1.000000e-08 rtol=1.000000e-03
    [      10] NumericalAnalytics KSPOuterResidual:  3.32046e-04
    [      10] NumericalAnalytics KSPOuterResidual(relative):  5.12260e-03
    [      10]         KSP it 2 norm(r) = 3.320458e-04  norm(r)/|b| = 5.122596e-03 ; atol=1.000000e-08 rtol=1.000000e-03
    [      10] NumericalAnalytics KSPOuterResidual:  2.61841e-05
    [      10] NumericalAnalytics KSPOuterResidual(relative):  4.03953e-04
    [      10]         KSP it 3 norm(r) = 2.618415e-05  norm(r)/|b| = 4.039528e-04 ; atol=1.000000e-08 rtol=1.000000e-03
    [      10] after ksp.rtol= 0.001 ksp.atol= 1e-08 ksp.converged= True ksp.its= 3 ksp.norm= 0.000471230197285 reason = 2
    [      10]   NumericalAnalytics NewtonIteration: 0, NewtonNorm:  2.61841e-05
    [      10]    Newton it 1 norm(r) =  2.61841e-05  		 norm(r)/(rtol*norm(r0)+atol) =  2.61672e-05
    [      10] SO_bas

```python

```

```python

```