4444from qiskit .circuit .gate import Gate
4545from qiskit .circuit .parameter import Parameter
4646from qiskit .circuit .exceptions import CircuitError
47+ from qiskit .utils import deprecate_func
4748from . import _classical_resource_map
4849from ._utils import sort_parameters
4950from .controlflow import ControlFlowOp , _builder_utils
@@ -1077,7 +1078,7 @@ def __init__(
10771078 self .name : str
10781079 """A human-readable name for the circuit."""
10791080 if name is None :
1080- self ._base_name = self .cls_prefix ()
1081+ self ._base_name = self ._cls_prefix ()
10811082 self ._name_update ()
10821083 elif not isinstance (name , str ):
10831084 raise CircuitError (
@@ -1400,24 +1401,47 @@ def _increment_instances(cls):
14001401 cls .instances += 1
14011402
14021403 @classmethod
1404+ @deprecate_func (
1405+ since = 1.2 ,
1406+ removal_timeline = "in the 2.0 release" ,
1407+ additional_msg = "This method is only used as an internal helper "
1408+ "and will be removed with no replacement." ,
1409+ )
14031410 def cls_instances (cls ) -> int :
14041411 """Return the current number of instances of this class,
14051412 useful for auto naming."""
14061413 return cls .instances
14071414
14081415 @classmethod
1416+ def _cls_instances (cls ) -> int :
1417+ """Return the current number of instances of this class,
1418+ useful for auto naming."""
1419+ return cls .instances
1420+
1421+ @classmethod
1422+ @deprecate_func (
1423+ since = 1.2 ,
1424+ removal_timeline = "in the 2.0 release" ,
1425+ additional_msg = "This method is only used as an internal helper "
1426+ "and will be removed with no replacement." ,
1427+ )
14091428 def cls_prefix (cls ) -> str :
14101429 """Return the prefix to use for auto naming."""
14111430 return cls .prefix
14121431
1432+ @classmethod
1433+ def _cls_prefix (cls ) -> str :
1434+ """Return the prefix to use for auto naming."""
1435+ return cls .prefix
1436+
14131437 def _name_update (self ) -> None :
14141438 """update name of instance using instance number"""
14151439 if not is_main_process ():
14161440 pid_name = f"-{ mp .current_process ().pid } "
14171441 else :
14181442 pid_name = ""
14191443
1420- self .name = f"{ self ._base_name } -{ self .cls_instances ()} { pid_name } "
1444+ self .name = f"{ self ._base_name } -{ self ._cls_instances ()} { pid_name } "
14211445
14221446 def has_register (self , register : Register ) -> bool :
14231447 """
@@ -1926,7 +1950,7 @@ def replace_var(var: expr.Var, cache: Mapping[expr.Var, expr.Var]) -> expr.Var:
19261950 mapped_qubits = dest .qubits
19271951 edge_map .update (zip (other .qubits , dest .qubits ))
19281952 else :
1929- mapped_qubits = dest .qbit_argument_conversion (qubits )
1953+ mapped_qubits = dest ._qbit_argument_conversion (qubits )
19301954 if len (mapped_qubits ) != other .num_qubits :
19311955 raise CircuitError (
19321956 f"Number of items in qubits parameter ({ len (mapped_qubits )} ) does not"
@@ -1942,7 +1966,7 @@ def replace_var(var: expr.Var, cache: Mapping[expr.Var, expr.Var]) -> expr.Var:
19421966 mapped_clbits = dest .clbits
19431967 edge_map .update (zip (other .clbits , dest .clbits ))
19441968 else :
1945- mapped_clbits = dest .cbit_argument_conversion (clbits )
1969+ mapped_clbits = dest ._cbit_argument_conversion (clbits )
19461970 if len (mapped_clbits ) != other .num_clbits :
19471971 raise CircuitError (
19481972 f"Number of items in clbits parameter ({ len (mapped_clbits )} ) does not"
@@ -1952,7 +1976,7 @@ def replace_var(var: expr.Var, cache: Mapping[expr.Var, expr.Var]) -> expr.Var:
19521976 raise CircuitError (
19531977 f"Duplicate clbits referenced in 'clbits' parameter: '{ mapped_clbits } '"
19541978 )
1955- edge_map .update (zip (other .clbits , dest .cbit_argument_conversion (clbits )))
1979+ edge_map .update (zip (other .clbits , dest ._cbit_argument_conversion (clbits )))
19561980
19571981 for gate , cals in other .calibrations .items ():
19581982 dest ._calibrations [gate ].update (cals )
@@ -2267,38 +2291,91 @@ def __getitem__(self, item):
22672291 return self ._data [item ]
22682292
22692293 @staticmethod
2294+ @deprecate_func (
2295+ since = 1.2 ,
2296+ removal_timeline = "in the 2.0 release" ,
2297+ additional_msg = "This method is only used as an internal helper "
2298+ "and will be removed with no replacement." ,
2299+ )
22702300 def cast (value : S , type_ : Callable [..., T ]) -> Union [S , T ]:
22712301 """Best effort to cast value to type. Otherwise, returns the value."""
22722302 try :
22732303 return type_ (value )
22742304 except (ValueError , TypeError ):
22752305 return value
22762306
2307+ @staticmethod
2308+ def _cast (value : S , type_ : Callable [..., T ]) -> Union [S , T ]:
2309+ """Best effort to cast value to type. Otherwise, returns the value."""
2310+ try :
2311+ return type_ (value )
2312+ except (ValueError , TypeError ):
2313+ return value
2314+
2315+ @deprecate_func (
2316+ since = 1.2 ,
2317+ removal_timeline = "in the 2.0 release" ,
2318+ additional_msg = "This method is only used as an internal helper "
2319+ "and will be removed with no replacement." ,
2320+ )
22772321 def qbit_argument_conversion (self , qubit_representation : QubitSpecifier ) -> list [Qubit ]:
22782322 """
22792323 Converts several qubit representations (such as indexes, range, etc.)
22802324 into a list of qubits.
22812325
22822326 Args:
2283- qubit_representation (Object): representation to expand
2327+ qubit_representation: Representation to expand.
22842328
22852329 Returns:
2286- List(Qubit): the resolved instances of the qubits.
2330+ The resolved instances of the qubits.
2331+ """
2332+
2333+ return self ._qbit_argument_conversion (qubit_representation )
2334+
2335+ def _qbit_argument_conversion (self , qubit_representation : QubitSpecifier ) -> list [Qubit ]:
2336+ """
2337+ Converts several qubit representations (such as indexes, range, etc.)
2338+ into a list of qubits.
2339+
2340+ Args:
2341+ qubit_representation: Representation to expand.
2342+
2343+ Returns:
2344+ The resolved instances of the qubits.
22872345 """
22882346 return _bit_argument_conversion (
22892347 qubit_representation , self .qubits , self ._qubit_indices , Qubit
22902348 )
22912349
2350+ @deprecate_func (
2351+ since = 1.2 ,
2352+ removal_timeline = "in the 2.0 release" ,
2353+ additional_msg = "This method is only used as an internal helper "
2354+ "and will be removed with no replacement." ,
2355+ )
22922356 def cbit_argument_conversion (self , clbit_representation : ClbitSpecifier ) -> list [Clbit ]:
22932357 """
22942358 Converts several classical bit representations (such as indexes, range, etc.)
22952359 into a list of classical bits.
22962360
22972361 Args:
2298- clbit_representation (Object): representation to expand
2362+ clbit_representation : Representation to expand.
22992363
23002364 Returns:
2301- List(tuple): Where each tuple is a classical bit.
2365+ A list of tuples where each tuple is a classical bit.
2366+ """
2367+ return self ._cbit_argument_conversion (clbit_representation )
2368+
2369+ def _cbit_argument_conversion (self , clbit_representation : ClbitSpecifier ) -> list [Clbit ]:
2370+ """
2371+ Converts several classical bit representations (such as indexes, range, etc.)
2372+ into a list of classical bits.
2373+
2374+ Args:
2375+ clbit_representation: Representation to expand.
2376+
2377+ Returns:
2378+ A list of tuples where each tuple is a classical bit.
23022379 """
23032380 return _bit_argument_conversion (
23042381 clbit_representation , self .clbits , self ._clbit_indices , Clbit
@@ -2317,7 +2394,7 @@ def _append_standard_gate(
23172394 if params is None :
23182395 params = []
23192396
2320- expanded_qargs = [self .qbit_argument_conversion (qarg ) for qarg in qargs or []]
2397+ expanded_qargs = [self ._qbit_argument_conversion (qarg ) for qarg in qargs or []]
23212398 for param in params :
23222399 Gate .validate_parameter (op , param )
23232400
@@ -2416,8 +2493,8 @@ def append(
24162493 " which are not in this circuit"
24172494 )
24182495
2419- expanded_qargs = [self .qbit_argument_conversion (qarg ) for qarg in qargs or []]
2420- expanded_cargs = [self .cbit_argument_conversion (carg ) for carg in cargs or []]
2496+ expanded_qargs = [self ._qbit_argument_conversion (qarg ) for qarg in qargs or []]
2497+ expanded_cargs = [self ._cbit_argument_conversion (carg ) for carg in cargs or []]
24212498
24222499 instructions = InstructionSet (resource_requester = circuit_scope .resolve_classical_resource )
24232500 # For Operations that are non-Instructions, we use the Instruction's default method
@@ -4416,7 +4493,9 @@ def barrier(self, *qargs: QubitSpecifier, label=None) -> InstructionSet:
44164493
44174494 if qargs :
44184495 # This uses a `dict` not a `set` to guarantee a deterministic order to the arguments.
4419- qubits = tuple ({q : None for qarg in qargs for q in self .qbit_argument_conversion (qarg )})
4496+ qubits = tuple (
4497+ {q : None for qarg in qargs for q in self ._qbit_argument_conversion (qarg )}
4498+ )
44204499 return self .append (
44214500 CircuitInstruction (Barrier (len (qubits ), label = label ), qubits , ()), copy = False
44224501 )
@@ -5448,7 +5527,7 @@ def mcx(
54485527
54495528 # check ancilla input
54505529 if ancilla_qubits :
5451- _ = self .qbit_argument_conversion (ancilla_qubits )
5530+ _ = self ._qbit_argument_conversion (ancilla_qubits )
54525531
54535532 try :
54545533 gate = available_implementations [mode ]
0 commit comments