docstr: Add artifact to dvc.yaml.
docstr_tok: ["Add","artifact","to","dvc.yaml","."]
code: def add(
      self, name: str, artifact: Artifact, dvcfile: Optional[str] = None
  ):
      """Add artifact to dvc.yaml."""
      with self.repo.scm_context(quiet=True):
          check_name_format(name)
          dvcyaml = Path(dvcfile or PROJECT_FILE)
          check_for_nested_dvc_repo(
              dvcyaml.relative_to(self.repo.root_dir)
              if dvcyaml.is_absolute()
              else dvcyaml
          )
  
          with modify_yaml(dvcyaml) as data:
              artifacts = data.setdefault("artifacts", {})
              artifacts.update({name: artifact.to_dict()})
  
          self.repo.scm_context.track_file(dvcfile)
  
      return artifacts.get(name)
  
imports: import os
  import posixpath
  from pathlib import Path
  from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple, Union
  from dvc.annotations import Artifact
  from dvc.dvcfile import PROJECT_FILE
  from dvc.exceptions import ArtifactNotFoundError, DvcException, FileExistsLocallyError, InvalidArgumentError
  from dvc.log import logger
  from dvc.utils import relpath, resolve_output
  from dvc.utils.objects import cached_property
  from dvc.utils.serialize import modify_yaml
label_desc: Use image node_id 4 for calling the Artifacts obj's underlying member method code with example usage: obj.add(name, artifact, dvcfile) and returns: artifacts