Ejemplo n.º 1
0
def test_invalid_initial_state_empty_circuit_qubits_specified(scheduler):
    simulator = xmon_simulator.XmonSimulator()

    with pytest.raises(ValueError):
        _ = simulate(simulator,
                     Circuit(),
                     scheduler,
                     qubit_order=[Q1, Q2],
                     initial_state=-1)

    with pytest.raises(ValueError):
        _ = simulate(simulator,
                     Circuit(),
                     scheduler,
                     qubit_order=[Q1, Q2],
                     initial_state=100)

    with pytest.raises(ValueError):
        _ = simulate(simulator,
                     Circuit(),
                     scheduler,
                     qubit_order=[Q1, Q2],
                     initial_state=np.array([0.0, 1.0], dtype=np.complex64))
Ejemplo n.º 2
0
def test_circuit_param_and_reps():
    sim = xmon_simulator.XmonSimulator()
    circuit = bit_flip_circuit(Symbol('a'), Symbol('b'))

    resolvers = [
        ParamResolver({
            'a': b1,
            'b': b2
        }) for b1 in range(2) for b2 in range(2)
    ]

    all_trials = sim.run_sweep(circuit, params=resolvers, repetitions=3)
    assert len(all_trials) == 4
    for result in all_trials:
        assert result.repetitions == 3
        expect_a = result.params['a'] == 1
        expect_b = result.params['b'] == 1
        np.testing.assert_equal(result.measurements['q1'], [[expect_a]] * 3)
        np.testing.assert_equal(result.measurements['q2'], [[expect_b]] * 3)
    # All parameters explored.
    assert (set(itertools.product([0, 1],
                                  [0, 1])) == {(r.params['a'], r.params['b'])
                                               for r in all_trials})
Ejemplo n.º 3
0
def test_circuit_bad_parameters():
    sim = xmon_simulator.XmonSimulator()
    circuit = bit_flip_circuit(Symbol('a'), Symbol('b'))
    with pytest.raises(TypeError):
        sim.run_sweep(circuit, params=3, repetitions=1)
Ejemplo n.º 4
0
def test_simulate_moment_steps_no_results():
    simulator = xmon_simulator.XmonSimulator()
    for step in simulator.simulate_moment_steps(basic_circuit()):
        assert len(step.measurements) == 0
Ejemplo n.º 5
0
def test_run_initial_state_int(scheduler):
    simulator = xmon_simulator.XmonSimulator()
    result = simulate(simulator, basic_circuit(), scheduler, initial_state=2)
    np.testing.assert_almost_equal(result.final_state,
                                   np.array([0.5, 0.5j, 0.5j, 0.5]))
Ejemplo n.º 6
0
def test_run_empty_circuit(scheduler):
    simulator = xmon_simulator.XmonSimulator()
    result = run(simulator, Circuit(), scheduler)
    assert len(result.measurements) == 0
Ejemplo n.º 7
0
def test_run_no_results(scheduler, use_processes):
    options = xmon_simulator.XmonOptions(use_processes=use_processes)
    simulator = xmon_simulator.XmonSimulator(options)
    result = run(simulator, basic_circuit(), scheduler)
    assert len(result.measurements) == 0