def test_set_qureg():
    """Test set qureg PRAGMA with PyQuEST interface"""
    env = utils.createQuestEnv()()
    qureg_density = utils.createDensityQureg()(2, env)
    qureg_wave = utils.createQureg()(2, env)
    cheat.initBlankState()(qureg=qureg_density)
    cheat.initBlankState()(qureg=qureg_wave)

    density_start = cheat.getDensityMatrix()(qureg_density)
    wave_start = cheat.getStateVector()(qureg_wave)

    set_wave = np.array([2, 1, 0, 1], dtype=complex)
    set_density = np.array([[1, 0, 2, 0],
                            [0, 2, 3, 3],
                            [3, 1, 0, 0],
                            [0, 1, 2, 0]], dtype=complex)

    pyquest_call_operation(operation=ops.PragmaSetStateVector(set_wave),
                           qureg=qureg_wave,
                           classical_bit_registers=dict(),
                           classical_float_registers=dict(),
                           classical_complex_registers=dict(),
                           output_bit_register_dict=dict(),)
    pyquest_call_operation(operation=ops.PragmaSetDensityMatrix(set_density),
                           qureg=qureg_density,
                           classical_bit_registers=dict(),
                           classical_float_registers=dict(),
                           classical_complex_registers=dict(),
                           output_bit_register_dict=dict(),)

    npt.assert_array_equal(density_start, [[0] * 4] * 4)
    npt.assert_array_equal(wave_start, [0] * 4)
    npt.assert_array_equal(set_wave, cheat.getStateVector()(qureg_wave))
    npt.assert_array_equal(set_density, cheat.getDensityMatrix()(qureg_density))

    utils.destroyQureg().call_interactive(qureg_wave, env)
    utils.destroyQureg().call_interactive(qureg_density, env)
    utils.destroyQuestEnv().call_interactive(env)
コード例 #2
0
 ops.SingleQubitGate(0, 0.1, 0.0, 0.0, 0.0, 0.0),
 ops.Hadamard(0),
 ops.PauliX(0),
 ops.PauliY(0),
 ops.PauliZ(0),
 ops.TGate(0),
 ops.SGate(0),
 ops.SqrtPauliX(0),
 ops.InvSqrtPauliX(0),
 ops.RotateX(0, 0.01),
 ops.RotateY(0, 0.01),
 ops.RotateZ(0, 0.01),
 ops.RotateAroundSphericalAxis(0, 0.01, 0.02, 0.03),
 ops.PragmaSetNumberOfMeasurements(20, 'ro'),
 ops.PragmaSetStateVector(np.array([0, 1], dtype=complex)),
 ops.PragmaSetDensityMatrix(np.array([[0, 0], [0, 1]], dtype=complex)),
 ops.PragmaDamping(0, 0.005, 0.02),
 ops.PragmaDephasing(0, 0.005, 0.02),
 ops.PragmaDepolarising(0, 0.005, 0.02),
 ops.PragmaRandomNoise(0, 0.005, 0.02, 0.01),
 ops.PragmaGeneralNoise(
     0, 0.005, np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]], dtype=float)),
 ops.PragmaConditional('ro', 0, Circuit()),
 ops.PragmaRepeatGate(3),
 ops.PragmaBoostNoise(0.004),
 ops.PragmaStopParallelBlock([0, 1], 0.002),
 ops.PragmaSleep([0, 1], 0.002),
 ops.PragmaActiveReset(0),
 ops.PragmaGlobalPhase(0.03),
 ops.MeasureQubit(0, 'ro', 0),
 ops.PragmaRepeatedMeasurement('ro', 20, {}),