def test_bloch_sphere_default_client_code_comp_basis():
    bloch_sphere = cirq_web.BlochSphere(state_vector=1)

    expected_client_code = f"""
        <script>
        renderBlochSphere('{bloch_sphere.id}', 5)
            .addVector(0.0, 0.0, -1.0);
        </script>
        """

    assert expected_client_code == bloch_sphere.get_client_code()
Beispiel #2
0
def test_bloch_sphere_default_client_code():
    state_vector = to_valid_state_vector([math.sqrt(2) / 2, math.sqrt(2) / 2])
    bloch_sphere = cirq_web.BlochSphere(state_vector=state_vector)

    expected_client_code = f"""
        <script>
        renderBlochSphere('{bloch_sphere.id}', 5)
            .addVector(1.0, 0.0, 0.0);
        </script>
        """

    assert expected_client_code == bloch_sphere.get_client_code()
def test_bloch_sphere_default_client_code():
    bloch_sphere = cirq_web.BlochSphere(
        state_vector=[1 / math.sqrt(2), 1 / math.sqrt(2)])

    expected_client_code = f"""
        <script>
        renderBlochSphere('{bloch_sphere.id}', 5)
            .addVector(1.0, 0.0, 0.0);
        </script>
        """

    assert expected_client_code == bloch_sphere.get_client_code()
Beispiel #4
0
def test_bloch_sphere_default_bundle_name():
    state_vector = to_valid_state_vector([math.sqrt(2) / 2, math.sqrt(2) / 2])
    bloch_sphere = cirq_web.BlochSphere(state_vector=state_vector)

    assert bloch_sphere.get_widget_bundle_name() == 'bloch_sphere.bundle.js'
Beispiel #5
0
def test_no_state_vector_given():
    with pytest.raises(ValueError):
        cirq_web.BlochSphere()
Beispiel #6
0
def test_valid_bloch_sphere_vector(state_vector):
    bloch_sphere = cirq_web.BlochSphere(state_vector=state_vector)
    bloch_vector = bloch_vector_from_state_vector(state_vector, 0)
    assert np.array_equal(bloch_vector, bloch_sphere.bloch_vector)
Beispiel #7
0
def test_invalid_bloch_sphere_radius(sphere_radius):
    with pytest.raises(ValueError):
        cirq_web.BlochSphere(sphere_radius=sphere_radius)
Beispiel #8
0
def test_valid_bloch_sphere_radius(sphere_radius):
    state_vector = to_valid_state_vector([math.sqrt(2) / 2, math.sqrt(2) / 2])
    bloch_sphere = cirq_web.BlochSphere(sphere_radius, state_vector)
    assert sphere_radius == bloch_sphere.sphere_radius
Beispiel #9
0
def test_init_bloch_sphere_type():
    state_vector = to_valid_state_vector([math.sqrt(2) / 2, math.sqrt(2) / 2])
    bloch_sphere = cirq_web.BlochSphere(state_vector=state_vector)
    assert isinstance(bloch_sphere, cirq_web.BlochSphere)
def test_valid_bloch_sphere_vector():
    state_vector = np.array([1 / math.sqrt(2), 1 / math.sqrt(2)])
    bloch_sphere = cirq_web.BlochSphere(state_vector=state_vector)
    bloch_vector = cirq.bloch_vector_from_state_vector(state_vector, 0)
    assert np.array_equal(bloch_vector, bloch_sphere.bloch_vector)
def test_valid_bloch_sphere_radius(sphere_radius):
    bloch_sphere = cirq_web.BlochSphere(sphere_radius,
                                        [1 / math.sqrt(2), 1 / math.sqrt(2)])
    assert sphere_radius == bloch_sphere.sphere_radius
def test_init_bloch_sphere_type():
    bloch_sphere = cirq_web.BlochSphere(
        state_vector=[1 / math.sqrt(2), 1 / math.sqrt(2)])
    assert isinstance(bloch_sphere, cirq_web.BlochSphere)