def main():
    """The main program loop.

    Simulates HHL with matrix input, and outputs Pauli observables of the resulting qubit state |x>.
    Expected observables are calculated from the expected solution |x>.
    """

    # Eigendecomposition:
    #   (4.537, [-0.971555, -0.0578339+0.229643j])
    #   (0.349, [-0.236813, 0.237270-0.942137j])
    # |b> = (0.64510-0.47848j, 0.35490-0.47848j)
    # |x> = (-0.0662724-0.214548j, 0.784392-0.578192j)
    A = np.array(
        [
            [4.30213466 - 6.01593490e-08j, 0.23531802 + 9.34386156e-01j],
            [0.23531882 - 9.34388383e-01j, 0.58386534 + 6.01593489e-08j],
        ]
    )
    t = 0.358166 * math.pi
    register_size = 4
    input_prep_gates = [cirq.rx(1.276359), cirq.rz(1.276359)]
    expected = (0.144130, 0.413217, -0.899154)

    # Set C to be the smallest eigenvalue that can be represented by the
    # circuit.
    C = 2 * math.pi / (2**register_size * t)

    # Simulate circuit.
    print('Expected observable outputs:')
    print('X =', expected[0])
    print('Y =', expected[1])
    print('Z =', expected[2])

    hhl = HHLAlgorithm(A, C, t, register_size, *input_prep_gates)
    print('Actual values without amplitude amplification: ')
    results = hhl.simulate_without_amplification(total_runs=5000)
    success_probability = hhl.print_results(results, num_runs=[5000, 5000, 5000])
    print(
        f'Success probability of a single run without amplitude amplification: '
        f'{success_probability}'
    )
    # We show that amplitude amplification obtains similar values using fewer simulations.
    # Because amplitude amplification continues until the algorithm succeeds, the number of
    # estimates is set to 5000 * success_probability to be roughly equivalent to 5000 runs
    # without amplitude amplification.
    print('Actual values with amplitude amplification: ')
    results, num_runs = hhl.simulate_with_amplification(
        total_estimates=int(5000 * success_probability)
    )
    success_probability = hhl.print_results(results, num_runs)
    print(
        f'Success probability of a single run with amplitude amplification: '
        f'{success_probability}'
    )
The main program loop.

    Simulates HHL with matrix input, and outputs Pauli observables of the resulting qubit state |x>.
    Expected observables are calculated from the expected solution |x>.
    
examples/hhl.py