intersect_param.py 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Copyright 2019 The FATE Authors. All Rights Reserved.
  5. #
  6. # Licensed under the Apache License, Version 2.0 (the "License");
  7. # you may not use this file except in compliance with the License.
  8. # You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. #
  18. import copy
  19. from federatedml.param.base_param import BaseParam, deprecated_param
  20. from federatedml.param.base_param import BaseParam
  21. from federatedml.util import consts, LOGGER
  22. DEFAULT_RANDOM_BIT = 128
  23. class EncodeParam(BaseParam):
  24. """
  25. Define the hash method for raw intersect method
  26. Parameters
  27. ----------
  28. salt: str
  29. the src id will be str = str + salt, default by empty string
  30. encode_method: {"none", "md5", "sha1", "sha224", "sha256", "sha384", "sha512", "sm3"}
  31. the hash method of src id, support md5, sha1, sha224, sha256, sha384, sha512, sm3, default by None
  32. base64: bool
  33. if True, the result of hash will be changed to base64, default by False
  34. """
  35. def __init__(self, salt='', encode_method='none', base64=False):
  36. super().__init__()
  37. self.salt = salt
  38. self.encode_method = encode_method
  39. self.base64 = base64
  40. def check(self):
  41. if type(self.salt).__name__ != "str":
  42. raise ValueError(
  43. "encode param's salt {} not supported, should be str type".format(
  44. self.salt))
  45. descr = "encode param's "
  46. self.encode_method = self.check_and_change_lower(self.encode_method,
  47. ["none", consts.MD5, consts.SHA1, consts.SHA224,
  48. consts.SHA256, consts.SHA384, consts.SHA512,
  49. consts.SM3],
  50. descr)
  51. if type(self.base64).__name__ != "bool":
  52. raise ValueError(
  53. "hash param's base64 {} not supported, should be bool type".format(self.base64))
  54. LOGGER.debug("Finish EncodeParam check!")
  55. LOGGER.warning(f"'EncodeParam' will be replaced by 'RAWParam' in future release."
  56. f"Please do not rely on current param naming in application.")
  57. return True
  58. class RAWParam(BaseParam):
  59. """
  60. Specify parameters for raw intersect method
  61. Parameters
  62. ----------
  63. use_hash: bool
  64. whether to hash ids for raw intersect
  65. salt: str
  66. the src id will be str = str + salt, default by empty string
  67. hash_method: str
  68. the hash method of src id, support md5, sha1, sha224, sha256, sha384, sha512, sm3, default by None
  69. base64: bool
  70. if True, the result of hash will be changed to base64, default by False
  71. join_role: {"guest", "host"}
  72. role who joins ids, supports "guest" and "host" only and effective only for raw.
  73. If it is "guest", the host will send its ids to guest and find the intersection of
  74. ids in guest; if it is "host", the guest will send its ids to host. Default by "guest";
  75. """
  76. def __init__(self, use_hash=False, salt='', hash_method='none', base64=False, join_role=consts.GUEST):
  77. super().__init__()
  78. self.use_hash = use_hash
  79. self.salt = salt
  80. self.hash_method = hash_method
  81. self.base64 = base64
  82. self.join_role = join_role
  83. def check(self):
  84. descr = "raw param's "
  85. self.check_boolean(self.use_hash, f"{descr}use_hash")
  86. self.check_string(self.salt, f"{descr}salt")
  87. self.hash_method = self.check_and_change_lower(self.hash_method,
  88. ["none", consts.MD5, consts.SHA1, consts.SHA224,
  89. consts.SHA256, consts.SHA384, consts.SHA512,
  90. consts.SM3],
  91. f"{descr}hash_method")
  92. self.check_boolean(self.base64, f"{descr}base_64")
  93. self.join_role = self.check_and_change_lower(self.join_role, [consts.GUEST, consts.HOST], f"{descr}join_role")
  94. LOGGER.debug("Finish RAWParam check!")
  95. return True
  96. class RSAParam(BaseParam):
  97. """
  98. Specify parameters for RSA intersect method
  99. Parameters
  100. ----------
  101. salt: str
  102. the src id will be str = str + salt, default ''
  103. hash_method: str
  104. the hash method of src id, support sha256, sha384, sha512, sm3, default sha256
  105. final_hash_method: str
  106. the hash method of result data string, support md5, sha1, sha224, sha256, sha384, sha512, sm3, default sha256
  107. split_calculation: bool
  108. if True, Host & Guest split operations for faster performance, recommended on large data set
  109. random_base_fraction: positive float
  110. if not None, generate (fraction * public key id count) of r for encryption and reuse generated r;
  111. note that value greater than 0.99 will be taken as 1, and value less than 0.01 will be rounded up to 0.01
  112. key_length: int
  113. value >= 1024, bit count of rsa key, default 1024
  114. random_bit: positive int
  115. it will define the size of blinding factor in rsa algorithm, default 128
  116. """
  117. def __init__(self, salt='', hash_method='sha256', final_hash_method='sha256',
  118. split_calculation=False, random_base_fraction=None, key_length=consts.DEFAULT_KEY_LENGTH,
  119. random_bit=DEFAULT_RANDOM_BIT):
  120. super().__init__()
  121. self.salt = salt
  122. self.hash_method = hash_method
  123. self.final_hash_method = final_hash_method
  124. self.split_calculation = split_calculation
  125. self.random_base_fraction = random_base_fraction
  126. self.key_length = key_length
  127. self.random_bit = random_bit
  128. def check(self):
  129. descr = "rsa param's "
  130. self.check_string(self.salt, f"{descr}salt")
  131. self.hash_method = self.check_and_change_lower(self.hash_method,
  132. [consts.SHA256, consts.SHA384, consts.SHA512, consts.SM3],
  133. f"{descr}hash_method")
  134. self.final_hash_method = self.check_and_change_lower(self.final_hash_method,
  135. [consts.MD5, consts.SHA1, consts.SHA224,
  136. consts.SHA256, consts.SHA384, consts.SHA512,
  137. consts.SM3],
  138. f"{descr}final_hash_method")
  139. self.check_boolean(self.split_calculation, f"{descr}split_calculation")
  140. if self.random_base_fraction:
  141. self.check_positive_number(self.random_base_fraction, descr)
  142. self.check_decimal_float(self.random_base_fraction, f"{descr}random_base_fraction")
  143. self.check_positive_integer(self.key_length, f"{descr}key_length")
  144. if self.key_length < 1024:
  145. raise ValueError(f"key length must be >= 1024")
  146. self.check_positive_integer(self.random_bit, f"{descr}random_bit")
  147. LOGGER.debug("Finish RSAParam parameter check!")
  148. return True
  149. class DHParam(BaseParam):
  150. """
  151. Define the hash method for DH intersect method
  152. Parameters
  153. ----------
  154. salt: str
  155. the src id will be str = str + salt, default ''
  156. hash_method: str
  157. the hash method of src id, support none, md5, sha1, sha 224, sha256, sha384, sha512, sm3, default sha256
  158. key_length: int, value >= 1024
  159. the key length of the commutative cipher p, default 1024
  160. """
  161. def __init__(self, salt='', hash_method='sha256', key_length=consts.DEFAULT_KEY_LENGTH):
  162. super().__init__()
  163. self.salt = salt
  164. self.hash_method = hash_method
  165. self.key_length = key_length
  166. def check(self):
  167. descr = "dh param's "
  168. self.check_string(self.salt, f"{descr}salt")
  169. self.hash_method = self.check_and_change_lower(self.hash_method,
  170. ["none", consts.MD5, consts.SHA1, consts.SHA224,
  171. consts.SHA256, consts.SHA384, consts.SHA512,
  172. consts.SM3],
  173. f"{descr}hash_method")
  174. self.check_positive_integer(self.key_length, f"{descr}key_length")
  175. if self.key_length < 1024:
  176. raise ValueError(f"key length must be >= 1024")
  177. LOGGER.debug("Finish DHParam parameter check!")
  178. return True
  179. class ECDHParam(BaseParam):
  180. """
  181. Define the hash method for ECDH intersect method
  182. Parameters
  183. ----------
  184. salt: str
  185. the src id will be str = str + salt, default ''
  186. hash_method: str
  187. the hash method of src id, support sha256, sha384, sha512, sm3, default sha256
  188. curve: str
  189. the name of curve, currently only support 'curve25519', which offers 128 bits of security
  190. """
  191. def __init__(self, salt='', hash_method='sha256', curve=consts.CURVE25519):
  192. super().__init__()
  193. self.salt = salt
  194. self.hash_method = hash_method
  195. self.curve = curve
  196. def check(self):
  197. descr = "ecdh param's "
  198. self.check_string(self.salt, f"{descr}salt")
  199. self.hash_method = self.check_and_change_lower(self.hash_method,
  200. [consts.SHA256, consts.SHA384, consts.SHA512,
  201. consts.SM3],
  202. f"{descr}hash_method")
  203. self.curve = self.check_and_change_lower(self.curve, [consts.CURVE25519], f"{descr}curve")
  204. LOGGER.debug("Finish ECDHParam parameter check!")
  205. return True
  206. class IntersectCache(BaseParam):
  207. def __init__(self, use_cache=False, id_type=consts.PHONE, encrypt_type=consts.SHA256):
  208. """
  209. Parameters
  210. ----------
  211. use_cache: bool
  212. whether to use cached ids; with ver1.7 and above, this param is ignored
  213. id_type
  214. with ver1.7 and above, this param is ignored
  215. encrypt_type
  216. with ver1.7 and above, this param is ignored
  217. """
  218. super().__init__()
  219. self.use_cache = use_cache
  220. self.id_type = id_type
  221. self.encrypt_type = encrypt_type
  222. def check(self):
  223. descr = "intersect_cache param's "
  224. # self.check_boolean(self.use_cache, f"{descr}use_cache")
  225. self.check_and_change_lower(self.id_type,
  226. [consts.PHONE, consts.IMEI],
  227. f"{descr}id_type")
  228. self.check_and_change_lower(self.encrypt_type,
  229. [consts.MD5, consts.SHA256],
  230. f"{descr}encrypt_type")
  231. class IntersectPreProcessParam(BaseParam):
  232. """
  233. Specify parameters for pre-processing and cardinality-only mode
  234. Parameters
  235. ----------
  236. false_positive_rate: float
  237. initial target false positive rate when creating Bloom Filter,
  238. must be <= 0.5, default 1e-3
  239. encrypt_method: str
  240. encrypt method for encrypting id when performing cardinality_only task,
  241. supports rsa only, default rsa;
  242. specify rsa parameter setting with RSAParam
  243. hash_method: str
  244. the hash method for inserting ids, support md5, sha1, sha 224, sha256, sha384, sha512, sm3,
  245. default sha256
  246. preprocess_method: str
  247. the hash method for encoding ids before insertion into filter, default sha256,
  248. only effective for preprocessing
  249. preprocess_salt: str
  250. salt to be appended to hash result by preprocess_method before insertion into filter,
  251. default '', only effective for preprocessing
  252. random_state: int
  253. seed for random salt generator when constructing hash functions,
  254. salt is appended to hash result by hash_method when performing insertion, default None
  255. filter_owner: str
  256. role that constructs filter, either guest or host, default guest,
  257. only effective for preprocessing
  258. """
  259. def __init__(self, false_positive_rate=1e-3, encrypt_method=consts.RSA, hash_method='sha256',
  260. preprocess_method='sha256', preprocess_salt='', random_state=None, filter_owner=consts.GUEST):
  261. super().__init__()
  262. self.false_positive_rate = false_positive_rate
  263. self.encrypt_method = encrypt_method
  264. self.hash_method = hash_method
  265. self.preprocess_method = preprocess_method
  266. self.preprocess_salt = preprocess_salt
  267. self.random_state = random_state
  268. self.filter_owner = filter_owner
  269. def check(self):
  270. descr = "intersect preprocess param's false_positive_rate "
  271. self.check_decimal_float(self.false_positive_rate, descr)
  272. self.check_positive_number(self.false_positive_rate, descr)
  273. if self.false_positive_rate > 0.5:
  274. raise ValueError(f"{descr} must be positive float no greater than 0.5")
  275. descr = "intersect preprocess param's encrypt_method "
  276. self.encrypt_method = self.check_and_change_lower(self.encrypt_method, [consts.RSA], descr)
  277. descr = "intersect preprocess param's random_state "
  278. if self.random_state:
  279. self.check_nonnegative_number(self.random_state, descr)
  280. descr = "intersect preprocess param's hash_method "
  281. self.hash_method = self.check_and_change_lower(self.hash_method,
  282. [consts.MD5, consts.SHA1, consts.SHA224,
  283. consts.SHA256, consts.SHA384, consts.SHA512,
  284. consts.SM3],
  285. descr)
  286. descr = "intersect preprocess param's preprocess_salt "
  287. self.check_string(self.preprocess_salt, descr)
  288. descr = "intersect preprocess param's preprocess_method "
  289. self.preprocess_method = self.check_and_change_lower(self.preprocess_method,
  290. [consts.MD5, consts.SHA1, consts.SHA224,
  291. consts.SHA256, consts.SHA384, consts.SHA512,
  292. consts.SM3],
  293. descr)
  294. descr = "intersect preprocess param's filter_owner "
  295. self.filter_owner = self.check_and_change_lower(self.filter_owner,
  296. [consts.GUEST, consts.HOST],
  297. descr)
  298. LOGGER.debug("Finish IntersectPreProcessParam parameter check!")
  299. return True
  300. @deprecated_param("random_bit", "join_role", "with_encode", "encode_params", "intersect_cache_param",
  301. "repeated_id_process", "repeated_id_owner", "allow_info_share", "info_owner", "with_sample_id")
  302. class IntersectParam(BaseParam):
  303. """
  304. Define the intersect method
  305. Parameters
  306. ----------
  307. intersect_method: str
  308. it supports 'rsa', 'raw', 'dh', 'ecdh', default by 'rsa'
  309. random_bit: positive int
  310. it will define the size of blinding factor in rsa algorithm, default 128
  311. note that this param will be deprecated in future, please use random_bit in RSAParam instead
  312. sync_intersect_ids: bool
  313. In rsa, 'sync_intersect_ids' is True means guest or host will send intersect results to the others, and False will not.
  314. while in raw, 'sync_intersect_ids' is True means the role of "join_role" will send intersect results and the others will get them.
  315. Default by True.
  316. join_role: str
  317. role who joins ids, supports "guest" and "host" only and effective only for raw.
  318. If it is "guest", the host will send its ids to guest and find the intersection of
  319. ids in guest; if it is "host", the guest will send its ids to host. Default by "guest";
  320. note this param will be deprecated in future version, please use 'join_role' in raw_params instead
  321. only_output_key: bool
  322. if false, the results of intersection will include key and value which from input data; if true, it will just include key from input
  323. data and the value will be empty or filled by uniform string like "intersect_id"
  324. with_encode: bool
  325. if True, it will use hash method for intersect ids, effective for raw method only;
  326. note that this param will be deprecated in future version, please use 'use_hash' in raw_params;
  327. currently if this param is set to True,
  328. specification by 'encode_params' will be taken instead of 'raw_params'.
  329. encode_params: EncodeParam
  330. effective only when with_encode is True;
  331. this param will be deprecated in future version, use 'raw_params' in future implementation
  332. raw_params: RAWParam
  333. effective for raw method only
  334. rsa_params: RSAParam
  335. effective for rsa method only
  336. dh_params: DHParam
  337. effective for dh method only
  338. ecdh_params: ECDHParam
  339. effective for ecdh method only
  340. join_method: {'inner_join', 'left_join'}
  341. if 'left_join', participants will all include sample_id_generator's (imputed) ids in output,
  342. default 'inner_join'
  343. new_sample_id: bool
  344. whether to generate new id for sample_id_generator's ids,
  345. only effective when join_method is 'left_join' or when input data are instance with match id,
  346. default False
  347. sample_id_generator: str
  348. role whose ids are to be kept,
  349. effective only when join_method is 'left_join' or when input data are instance with match id,
  350. default 'guest'
  351. intersect_cache_param: IntersectCacheParam
  352. specification for cache generation,
  353. with ver1.7 and above, this param is ignored.
  354. run_cache: bool
  355. whether to store Host's encrypted ids, only valid when intersect method is 'rsa', 'dh', 'ecdh', default False
  356. cardinality_only: bool
  357. whether to output estimated intersection count(cardinality);
  358. if sync_cardinality is True, then sync cardinality count with host(s)
  359. cardinality_method: string
  360. specify which intersect method to use for coutning cardinality, default "ecdh";
  361. note that with "rsa", estimated cardinality will be produced;
  362. while "dh" and "ecdh" method output exact cardinality, it only supports single-host task
  363. sync_cardinality: bool
  364. whether to sync cardinality with all participants, default False,
  365. only effective when cardinality_only set to True
  366. run_preprocess: bool
  367. whether to run preprocess process, default False
  368. intersect_preprocess_params: IntersectPreProcessParam
  369. used for preprocessing and cardinality_only mode
  370. repeated_id_process: bool
  371. if true, intersection will process the ids which can be repeatable;
  372. in ver 1.7 and above,repeated id process
  373. will be automatically applied to data with instance id, this param will be ignored
  374. repeated_id_owner: str
  375. which role has the repeated id; in ver 1.7 and above, this param is ignored
  376. allow_info_share: bool
  377. in ver 1.7 and above, this param is ignored
  378. info_owner: str
  379. in ver 1.7 and above, this param is ignored
  380. with_sample_id: bool
  381. data with sample id or not, default False; in ver 1.7 and above, this param is ignored
  382. """
  383. def __init__(self, intersect_method: str = consts.RSA, random_bit=DEFAULT_RANDOM_BIT, sync_intersect_ids=True,
  384. join_role=consts.GUEST, only_output_key: bool = False,
  385. with_encode=False, encode_params=EncodeParam(),
  386. raw_params=RAWParam(), rsa_params=RSAParam(), dh_params=DHParam(), ecdh_params=ECDHParam(),
  387. join_method=consts.INNER_JOIN, new_sample_id: bool = False, sample_id_generator=consts.GUEST,
  388. intersect_cache_param=IntersectCache(), run_cache: bool = False,
  389. cardinality_only: bool = False, sync_cardinality: bool = False, cardinality_method=consts.ECDH,
  390. run_preprocess: bool = False,
  391. intersect_preprocess_params=IntersectPreProcessParam(),
  392. repeated_id_process=False, repeated_id_owner=consts.GUEST,
  393. with_sample_id=False, allow_info_share: bool = False, info_owner=consts.GUEST):
  394. super().__init__()
  395. self.intersect_method = intersect_method
  396. self.random_bit = random_bit
  397. self.sync_intersect_ids = sync_intersect_ids
  398. self.join_role = join_role
  399. self.with_encode = with_encode
  400. self.encode_params = copy.deepcopy(encode_params)
  401. self.raw_params = copy.deepcopy(raw_params)
  402. self.rsa_params = copy.deepcopy(rsa_params)
  403. self.only_output_key = only_output_key
  404. self.sample_id_generator = sample_id_generator
  405. self.intersect_cache_param = copy.deepcopy(intersect_cache_param)
  406. self.run_cache = run_cache
  407. self.repeated_id_process = repeated_id_process
  408. self.repeated_id_owner = repeated_id_owner
  409. self.allow_info_share = allow_info_share
  410. self.info_owner = info_owner
  411. self.with_sample_id = with_sample_id
  412. self.join_method = join_method
  413. self.new_sample_id = new_sample_id
  414. self.dh_params = copy.deepcopy(dh_params)
  415. self.cardinality_only = cardinality_only
  416. self.sync_cardinality = sync_cardinality
  417. self.cardinality_method = cardinality_method
  418. self.run_preprocess = run_preprocess
  419. self.intersect_preprocess_params = copy.deepcopy(intersect_preprocess_params)
  420. self.ecdh_params = copy.deepcopy(ecdh_params)
  421. def check(self):
  422. descr = "intersect param's "
  423. self.intersect_method = self.check_and_change_lower(self.intersect_method,
  424. [consts.RSA, consts.RAW, consts.DH, consts.ECDH],
  425. f"{descr}intersect_method")
  426. if self._warn_to_deprecate_param("random_bit", descr, "rsa_params' 'random_bit'"):
  427. if "rsa_params.random_bit" in self.get_user_feeded():
  428. raise ValueError(f"random_bit and rsa_params.random_bit should not be set simultaneously")
  429. self.rsa_params.random_bit = self.random_bit
  430. self.check_boolean(self.sync_intersect_ids, f"{descr}intersect_ids")
  431. if self._warn_to_deprecate_param("encode_param", "", ""):
  432. if "raw_params" in self.get_user_feeded():
  433. raise ValueError(f"encode_param and raw_params should not be set simultaneously")
  434. else:
  435. self.callback_param.callbacks = ["PerformanceEvaluate"]
  436. if self._warn_to_deprecate_param("join_role", descr, "raw_params' 'join_role'"):
  437. if "raw_params.join_role" in self.get_user_feeded():
  438. raise ValueError(f"join_role and raw_params.join_role should not be set simultaneously")
  439. self.raw_params.join_role = self.join_role
  440. self.check_boolean(self.only_output_key, f"{descr}only_output_key")
  441. self.join_method = self.check_and_change_lower(self.join_method, [consts.INNER_JOIN, consts.LEFT_JOIN],
  442. f"{descr}join_method")
  443. self.check_boolean(self.new_sample_id, f"{descr}new_sample_id")
  444. self.sample_id_generator = self.check_and_change_lower(self.sample_id_generator,
  445. [consts.GUEST, consts.HOST],
  446. f"{descr}sample_id_generator")
  447. if self.join_method == consts.LEFT_JOIN:
  448. if not self.sync_intersect_ids:
  449. raise ValueError(f"Cannot perform left join without sync intersect ids")
  450. self.check_boolean(self.run_cache, f"{descr} run_cache")
  451. if self._warn_to_deprecate_param("encode_params", descr, "raw_params") or \
  452. self._warn_to_deprecate_param("with_encode", descr, "raw_params' 'use_hash'"):
  453. # self.encode_params.check()
  454. if "with_encode" in self.get_user_feeded() and "raw_params.use_hash" in self.get_user_feeded():
  455. raise ValueError(f"'raw_params' and 'encode_params' should not be set simultaneously.")
  456. if "raw_params" in self.get_user_feeded() and "encode_params" in self.get_user_feeded():
  457. raise ValueError(f"'raw_params' and 'encode_params' should not be set simultaneously.")
  458. LOGGER.warning(f"Param values from 'encode_params' will override 'raw_params' settings.")
  459. self.raw_params.use_hash = self.with_encode
  460. self.raw_params.hash_method = self.encode_params.encode_method
  461. self.raw_params.salt = self.encode_params.salt
  462. self.raw_params.base64 = self.encode_params.base64
  463. self.raw_params.check()
  464. self.rsa_params.check()
  465. self.dh_params.check()
  466. self.ecdh_params.check()
  467. self.check_boolean(self.cardinality_only, f"{descr}cardinality_only")
  468. self.check_boolean(self.sync_cardinality, f"{descr}sync_cardinality")
  469. self.check_boolean(self.run_preprocess, f"{descr}run_preprocess")
  470. self.intersect_preprocess_params.check()
  471. if self.cardinality_only:
  472. if self.cardinality_method not in [consts.RSA, consts.DH, consts.ECDH]:
  473. raise ValueError(f"cardinality-only mode only support rsa, dh, ecdh.")
  474. if self.cardinality_method == consts.RSA and self.rsa_params.split_calculation:
  475. raise ValueError(f"cardinality-only mode only supports unified calculation.")
  476. if self.run_preprocess:
  477. if self.intersect_preprocess_params.false_positive_rate < 0.01:
  478. raise ValueError(f"for preprocessing ids, false_positive_rate must be no less than 0.01")
  479. if self.cardinality_only:
  480. raise ValueError(f"cardinality_only mode cannot run preprocessing.")
  481. if self.run_cache:
  482. if self.intersect_method not in [consts.RSA, consts.DH, consts.ECDH]:
  483. raise ValueError(f"Only rsa, dh, or ecdh method supports cache.")
  484. if self.intersect_method == consts.RSA and self.rsa_params.split_calculation:
  485. raise ValueError(f"RSA split_calculation does not support cache.")
  486. if self.cardinality_only:
  487. raise ValueError(f"cache is not available for cardinality_only mode.")
  488. if self.run_preprocess:
  489. raise ValueError(f"Preprocessing does not support cache.")
  490. deprecated_param_list = ["repeated_id_process", "repeated_id_owner", "intersect_cache_param",
  491. "allow_info_share", "info_owner", "with_sample_id"]
  492. for param in deprecated_param_list:
  493. self._warn_deprecated_param(param, descr)
  494. LOGGER.debug("Finish intersect parameter check!")
  495. return True