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()
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()
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'
def test_no_state_vector_given(): with pytest.raises(ValueError): cirq_web.BlochSphere()
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)
def test_invalid_bloch_sphere_radius(sphere_radius): with pytest.raises(ValueError): cirq_web.BlochSphere(sphere_radius=sphere_radius)
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
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)