Пример #1
0
    def test_zz(self):
        """
        Run the simulator with unitary noise.
        Then verify that the calculated ZZ matches the zz parameter.
        """

        num_of_gates = np.arange(0, 60, 10)
        gate_time = 0.1
        qubits = [0]
        spectators = [1]

        # Generate experiments
        circs, xdata, osc_freq = zz_circuits(num_of_gates,
                                             gate_time,
                                             qubits,
                                             spectators,
                                             nosc=2)

        # Set the simulator with ZZ
        zz_expected = 0.1
        zz_unitary = np.eye(4, dtype=complex)
        zz_unitary[3, 3] = np.exp(1j * 2 * np.pi * zz_expected * gate_time)
        error = coherent_unitary_error(zz_unitary)
        noise_model = NoiseModel()
        noise_model.add_nonlocal_quantum_error(error, 'id', [0], [0, 1])

        # Run the simulator
        backend = qiskit.Aer.get_backend('qasm_simulator')
        shots = 100
        # For demonstration purposes split the execution into two jobs
        backend_result = qiskit.execute(circs,
                                        backend,
                                        shots=shots,
                                        seed_simulator=SEED,
                                        noise_model=noise_model,
                                        optimization_level=0).result()

        initial_a = 0.5
        initial_c = 0.5
        initial_f = osc_freq
        initial_phi = 0.0

        ZZFitter(backend_result,
                 xdata,
                 qubits,
                 spectators,
                 fit_p0=[initial_a, initial_f, initial_phi, initial_c],
                 fit_bounds=([-0.5, 0, -np.pi,
                              -0.5], [1.5, 2 * osc_freq, np.pi, 1.5]))
def zz_circuit_execution() -> Tuple[qiskit.result.Result,
                                    np.array,
                                    List[int],
                                    List[int],
                                    float,
                                    float]:
    """
    Create ZZ circuits and simulate them.

    Returns:
        *   Backend result.
        *   xdata.
        *   Qubits for the ZZ measurement.
        *   Spectators.
        *   ZZ parameter that used in the circuit creation
        *   Frequency.
    """

    num_of_gates = np.arange(0, 60, 10)
    gate_time = 0.1
    qubits = [0]
    spectators = [1]

    # Generate experiments
    circs, xdata, omega = zz_circuits(num_of_gates,
                                      gate_time, qubits,
                                      spectators, nosc=2)

    # Set the simulator with ZZ
    zz_value = 0.1
    zz_unitary = np.eye(4, dtype=complex)
    zz_unitary[3, 3] = np.exp(1j*2*np.pi*zz_value*gate_time)
    error = coherent_unitary_error(zz_unitary)
    noise_model = NoiseModel()
    noise_model.add_nonlocal_quantum_error(error, 'id', [0], [0, 1])

    # Run the simulator
    backend = qiskit.Aer.get_backend('qasm_simulator')
    shots = 100

    backend_result = qiskit.execute(circs, backend,
                                    shots=shots,
                                    seed_simulator=SEED,
                                    noise_model=noise_model,
                                    optimization_level=0).result()

    return backend_result, xdata, qubits, spectators, zz_value, omega
Пример #3
0
#  difference in frequency between experiments
number_of_gates = np.arange(0, 150, 5)    # number of identity gates per circuit
                                          #  ?: how did we get 150? 
gate_time = 0.1                           # time of running on a single gate
                                          # ?: what is the zz rate?

# Selects qubits whose ZZ will be measured
qubits = [0]        # measuring qubit 0?
spectators = [1]    # qubits to "flip the state" (i.e., measure energy shift
                    #  between qubits and spectators)

# Generates experiments.
oscillations_count = 2

circuits, delay_times, oscillation_freq = zz_circuits(number_of_gates,
                                                      gate_time, 
                                                      qubits, spectators,
                                                      nosc = oscillations_count)

## Splits circuits into multiple jobs, giving results to fitter as a list.
# Sets simulator with ZZ
unknown_factor = 0.02 # ?: what is this? ground state energy frequency (E=hw)?
time_evolver = np.exp(1j * 2 * np.pi * unknown_factor * gate_time)
zz_unitary = np.eye(4, dtype=complex)
zz_unitary[3,3] = time_evolver

error = coherent_unitary_error(zz_unitary)    # for applying to qubits in noise
                                              #  model below
my_noise_model = NoiseModel()
error_instructions = 'id'
noise_qubits = qubits + spectators
my_noise_model.add_nonlocal_quantum_error(error, error_instructions, qubits,