Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(samples): added create feature and create entity type samples and tests #984

Merged
merged 25 commits into from
Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b687093
feat: SDK feature store samples (create/delete fs)
nayaknishant Jan 27, 2022
5e1aef1
feat: adding to conftest.py
nayaknishant Jan 27, 2022
f9ea78f
docs(samples): fixed testing
nayaknishant Jan 27, 2022
c9c131d
docs(samples): fixed testing
nayaknishant Jan 27, 2022
827f228
docs(samples): fixed testing
nayaknishant Jan 27, 2022
6929a8f
Merge branch 'googleapis:main' into main
nayaknishant Jan 28, 2022
7621664
docs(samples) added changes
nayaknishant Feb 2, 2022
b3bec5e
docs(samples): style issues
nayaknishant Feb 2, 2022
1d01651
Merge branch 'main' into main
nayaknishant Feb 22, 2022
d217a8d
adding create entity
nayaknishant Jan 28, 2022
7620809
docs(samples): added create feature and entity type
nayaknishant Jan 28, 2022
bd8899e
docs(samples): edited test
nayaknishant Jan 31, 2022
ecbe0cd
docs(samples) edited style
nayaknishant Jan 31, 2022
c03182e
moving constants
nayaknishant Feb 23, 2022
9690114
fixed dates
nayaknishant Feb 23, 2022
42fffc9
Merge branch 'googleapis:main' into nn-create-delete
nayaknishant Feb 24, 2022
209ec83
Update samples/model-builder/create_featurestore_sample_test.py
nayaknishant Feb 24, 2022
0c7501e
Update samples/model-builder/test_constants.py
nayaknishant Feb 24, 2022
41d8fdd
Update samples/model-builder/create_featurestore_sample_test.py
nayaknishant Feb 24, 2022
b19fbf0
docs(samples): add samples to create/delete featurestore (#980)
nayaknishant Feb 24, 2022
a1815fc
Update samples/model-builder/test_constants.py
nayaknishant Feb 24, 2022
5c38dc2
moving constants
nayaknishant Feb 23, 2022
4343293
added variables, made fixes, fixed spelling
nayaknishant Feb 24, 2022
56f566d
Merge branch 'main' into nn-create-delete
nayaknishant Feb 24, 2022
81d62f1
Merge branch 'main' into nn-create-delete
nayaknishant Feb 25, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions samples/model-builder/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,3 +364,47 @@ def mock_endpoint_explain(mock_endpoint):
with patch.object(mock_endpoint, "explain") as mock_endpoint_explain:
mock_get_endpoint.return_value = mock_endpoint
yield mock_endpoint_explain


"""
----------------------------------------------------------------------------
FeatureStore Fixtures
----------------------------------------------------------------------------
"""


@pytest.fixture
def mock_featurestore():
mock = MagicMock(aiplatform.featurestore.Featurestore)
yield mock


@pytest.fixture
def mock_get_featurestore(mock_featurestore):
with patch.object(aiplatform.featurestore, "Featurestore") as mock_get_featurestore:
mock_get_featurestore.return_value = mock_featurestore
yield mock_get_featurestore


@pytest.fixture
def mock_create_featurestore():
with patch.object(aiplatform.Featurestore, "create") as mock:
yield mock


@pytest.fixture
def mock_create_entity_type():
with patch.object(aiplatform.EntityType, "create") as mock:
nayaknishant marked this conversation as resolved.
Show resolved Hide resolved
yield mock

nayaknishant marked this conversation as resolved.
Show resolved Hide resolved

@pytest.fixture
def mock_create_feature():
with patch.object(aiplatform.Feature, "create") as mock:
yield mock


@pytest.fixture
def mock_delete_featurestore(mock_featurestore):
with patch.object(mock_featurestore, "delete") as mock_delete_featurestore:
yield mock_delete_featurestore
35 changes: 35 additions & 0 deletions samples/model-builder/create_entity_type_sample.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


# [START aiplatform_sdk_create_entity_type_sample]
from google.cloud import aiplatform


def create_entity_type_sample(
project: str, location: str, entity_type_id: str, featurestore_name: str,
):

aiplatform.init(project=project, location=location)

fs = aiplatform.EntityType.create(
entity_type_id=entity_type_id, featurestore_name=featurestore_name
)

fs.wait()

nayaknishant marked this conversation as resolved.
Show resolved Hide resolved
return fs


# [END aiplatform_sdk_create_entity_type_sample]
35 changes: 35 additions & 0 deletions samples/model-builder/create_entity_type_sample_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import create_entity_type_sample
import test_constants as constants


def test_create_entity_type_sample(mock_sdk_init, mock_create_entity_type):

create_entity_type_sample.create_entity_type_sample(
project=constants.PROJECT,
location=constants.LOCATION,
entity_type_id=constants.ENTITY_TYPE_ID,
featurestore_name=constants.FEAUTURESTORE_NAME,
)

mock_sdk_init.assert_called_once_with(
project=constants.PROJECT, location=constants.LOCATION
)

mock_create_entity_type.assert_called_once_with(
entity_type_id=constants.ENTITY_TYPE_ID,
featurestore_name=constants.FEAUTURESTORE_NAME,
)
43 changes: 43 additions & 0 deletions samples/model-builder/create_feature_sample.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


# [START aiplatform_sdk_create_feature_sample]
from google.cloud import aiplatform


def create_feature_sample(
project: str,
location: str,
feature_id: str,
value_type: str,
entity_type_name: str,
featurestore_id: str,
):

aiplatform.init(project=project, location=location)

fs = aiplatform.Feature.create(
feature_id=feature_id,
value_type=value_type,
entity_type_name=entity_type_name,
featurestore_id=featurestore_id,
nayaknishant marked this conversation as resolved.
Show resolved Hide resolved
)

fs.wait()

return fs
nayaknishant marked this conversation as resolved.
Show resolved Hide resolved


# [END aiplatform_sdk_create_feature_sample]
39 changes: 39 additions & 0 deletions samples/model-builder/create_feature_sample_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import create_feature_sample
import test_constants as constants


def test_create_feature_sample(mock_sdk_init, mock_create_feature):

create_feature_sample.create_feature_sample(
project=constants.PROJECT,
location=constants.LOCATION,
feature_id=constants.FEATURE_ID,
value_type=constants.FEATURE_VALUE_TYPE,
entity_type_name=constants.ENTITY_TYPE_ID,
featurestore_id=constants.FEAUTURESTORE_NAME,
)

mock_sdk_init.assert_called_once_with(
project=constants.PROJECT, location=constants.LOCATION
)

mock_create_feature.assert_called_once_with(
feature_id=constants.FEATURE_ID,
value_type=constants.FEATURE_VALUE_TYPE,
entity_type_name=constants.ENTITY_TYPE_ID,
featurestore_id=constants.FEAUTURESTORE_NAME,
)
nayaknishant marked this conversation as resolved.
Show resolved Hide resolved
41 changes: 41 additions & 0 deletions samples/model-builder/create_featurestore_sample.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


# [START aiplatform_sdk_create_featurestore_sample]
from google.cloud import aiplatform


def create_featurestore_sample(
project: str,
location: str,
featurestore_id: str,
online_store_fixed_node_count: int = 1,
sync: bool = True,
):

aiplatform.init(project=project, location=location)

fs = aiplatform.Featurestore.create(
featurestore_id=featurestore_id,
online_store_fixed_node_count=online_store_fixed_node_count,
sync=sync,
)

fs.wait()

return fs


# [END aiplatform_sdk_create_featurestore_sample]
37 changes: 37 additions & 0 deletions samples/model-builder/create_featurestore_sample_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import create_featurestore_sample
import test_constants as constants


def test_create_featurestore_sample(mock_sdk_init, mock_create_featurestore):

create_featurestore_sample.create_featurestore_sample(
project=constants.PROJECT,
location=constants.LOCATION,
featurestore_id=constants.FEAUTURESTORE_NAME,
online_store_fixed_node_count=constants.ONLINE_STORE_FIXED_NODE_COUNT,
sync=constants.SYNC,
)

mock_sdk_init.assert_called_once_with(
project=constants.PROJECT, location=constants.LOCATION
)

mock_create_featurestore.assert_called_once_with(
featurestore_id=constants.FEAUTURESTORE_NAME,
online_store_fixed_node_count=constants.ONLINE_STORE_FIXED_NODE_COUNT,
sync=constants.SYNC,
)
34 changes: 34 additions & 0 deletions samples/model-builder/delete_featurestore_sample.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


# [START aiplatform_sdk_delete_featurestore_sample]
from google.cloud import aiplatform


def delete_featurestore_sample(
project: str,
location: str,
featurestore_name: str,
sync: bool = True,
force: bool = True,
):

aiplatform.init(project=project, location=location)

fs = aiplatform.featurestore.Featurestore(featurestore_name=featurestore_name)
fs.delete(sync=sync, force=force)


# [END aiplatform_sdk_delete_featurestore_sample]
41 changes: 41 additions & 0 deletions samples/model-builder/delete_featurestore_sample_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import delete_featurestore_sample
import test_constants as constants


def test_delete_featurestore_sample(
mock_sdk_init, mock_get_featurestore, mock_delete_featurestore
):

delete_featurestore_sample.delete_featurestore_sample(
project=constants.PROJECT,
location=constants.LOCATION,
featurestore_name=constants.FEAUTURESTORE_NAME,
sync=constants.SYNC,
force=constants.FORCE,
)

mock_sdk_init.assert_called_once_with(
project=constants.PROJECT, location=constants.LOCATION
)

mock_get_featurestore.assert_called_once_with(
featurestore_name=constants.FEAUTURESTORE_NAME
)

mock_delete_featurestore.assert_called_once_with(
sync=constants.SYNC, force=constants.FORCE
)
9 changes: 9 additions & 0 deletions samples/model-builder/test_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,12 @@
)
PYTHON_MODULE_NAME = "trainer.task"
MODEL_TYPE = "CLOUD"

# Feature store constants
FEAUTURESTORE_NAME = "featurestore_sample"
ENTITY_TYPE_ID = "entity_type_sample"
nayaknishant marked this conversation as resolved.
Show resolved Hide resolved
FEATURE_ID = "feature_sample"
FEATURE_VALUE_TYPE = "INT64"
ONLINE_STORE_FIXED_NODE_COUNT = 1
SYNC = True
FORCE = True