isqtools.circuits package¶
Submodules¶
isqtools.circuits.abstract_circuit module¶
Abstract quantum circuit. The core of current quantum circuits is the Qcis instruction set. The qcis file compiled by the isq compiler (icqc) is the main quantum circuit construction method, and other methods are not recommended.
- class AbstractCircuit(backend, sample, shots=100)¶
Bases:
ABC
Abstract quantum circuit.
- backend¶
The backend on which the task runs can be a simulator or hardware.
- sample¶
Whether to enable sampling mode. When the backend is a simulator, you can
sample
orprobs
. If the backend is hardware, you can only enable the sampling mode.
- shots¶
When the sampling mode is enabled, this parameter can specify the shots number.
- Parameters:
backend (
AbstractBackend
)sample (
bool
)shots (
int
)
- dict2array(result_dicts)¶
Transfer measurement results from Dict to Array.
- Parameters:
result_dicts (
dict
) – Use a dict to represent measurements, for example:{"00": 10, "01": 25, "10": 30, "11": 35}
.- Return type:
ndarray
- Returns:
Use array to represent the measurement results, arranged in binary order, for example:
[0.1, 0.25, 0.3, 0.35]
.
- abstractmethod measure(**kw)¶
Taking measurements on quantum circuits.
- abstractmethod pauli_measure(**kw)¶
Taking Pauli measurements on quantum circuits.
- sort_dict(result_dicts)¶
After the python >= 3.6, the dict will save the order. Use this method to sort the measurement results dictionary in binary.
- Parameters:
result_dicts (
dict
)- Return type:
dict
isqtools.circuits.isq_circuit module¶
Isq quantum circuit.
Use isqc
to generate qcis files, and generate quantum circuits by reading
qcis files. IsqCircuit is our recommended way to build quantum circuits.
- class IsqCircuit(file=None, backend=None, sample=False, shots=100, int_param=None, double_param=None, **kw)¶
Bases:
AbstractCircuit
IsQ quantum circuit class.
- backend¶
The backend on which the task runs, such as a simulator or hardware.
- sample¶
Whether to enable sampling mode. For simulators, supports
sample
orprobs
modes. For hardware, only sampling mode is supported.
- shots¶
Specifies the number of shots when sampling mode is enabled.
- qcis¶
Qcis instruction set for quantum circuits.
- Parameters:
file (
str
|None
)backend (
AbstractBackend
|None
)sample (
bool
)shots (
int
)int_param (
Sequence
[int
] |int
|None
)double_param (
Sequence
[float
] |float
|None
)
Initialization of isq quantum circuits.
- Parameters:
file (
str
|None
) –The file path. It is recommended to use full paths, be careful when using relative paths. 1) When the file extension is
.isq
, the isq file will becompiled into qcis.
When the extension of the file is
qcis
, read the file directly.When the extension of the file is
so
, it will be calledgen_qcis_from_so
to process theso
file to generate qcis.
backend (
AbstractBackend
|None
) – The backend on which the task runs can be a simulator or hardware.sample (
bool
) – Whether to enable sampling mode. When the backend is a simulator, you cansample
orprobs
. If the backend is hardware, you can only enable the sampling mode.shots (
int
) – When the sampling mode is enabled, this parameter can specify the shots number.int_param (
Sequence
[int
] |int
|None
) – Int data when compiling qcis.double_param (
Sequence
[float
] |float
|None
) – Double data when compiling qcis.**kw – Optional parameters.
- Raises:
IsqCircuitError – Check the extension of the
file
.
- measure(**kw)¶
Taking measurements on quantum circuits.
- Parameters:
**kw – Corresponding to the parameters in qcis and the
param
in isq file.- Return type:
dict
[str
,int
] |Any
- Returns:
Depending on whether to sample or not, the measurement result is obtained.
- pauli_measure(**kw)¶
Taking Pauli measurements on quantum circuits.
- Parameters:
**kw – Corresponding to the parameters in qcis and the
param
in isq file.- Return type:
Any
- Returns:
Depending on whether to sample or not, the measurement result is obtained. The measurement result will get the final result according to the rules of Pauli operation. This measurement method needs to implement the corresponding Pauli measurement in the isq file.
- state(**kw)¶
Get the simulated quantum state.
- Parameters:
**kw – Corresponding to the parameters in qcis and the
param
in isq file.- Return type:
Any
- Returns:
State vector.
- Raises:
IsqCircuitError – This method can only be used in non-sample.
- exception IsqCircuitError¶
Bases:
Exception
IsQ quantum circuits error.
isqtools.circuits.str_circuit module¶
Python quantum circuit class.
We recommend using isqc
to compile and generate the Qics instruction set to
build quantum circuits. However, to guarantee support for building circuits
via python, we built StrCircuit
. This class constructs quantum circuits in
the form of strings. This method cannot use the advanced features of isqc
and is not recommended.
- class StrCircuit(num_qubits, backend, sample=False, shots=100)¶
Bases:
AbstractCircuit
Python string quantum circuit class.
- num_qubits¶
Number of qubits simulated.
- backend¶
The backend on which the task runs can be a simulator or hardware.
- sample¶
Whether to enable sampling mode. When the backend is a simulator, you can
sample
orprobs
. If the backend is hardware, you can only enable the sampling mode.
- shots¶
When the sampling mode is enabled, this parameter can specify the shots number.
- qcis_list¶
Use list to record each Qcis instruction set.
- Parameters:
num_qubits (
int
|None
)backend (
AbstractBackend
)sample (
bool
)shots (
int
)
- CNOT(qubit_control, qubit_target)¶
- Parameters:
qubit_control (
int
)qubit_target (
int
)
- Return type:
None
- CX(qubit_control, qubit_target)¶
- Parameters:
qubit_control (
int
)qubit_target (
int
)
- Return type:
None
- CY(qubit_control, qubit_target)¶
- Parameters:
qubit_control (
int
)qubit_target (
int
)
- Return type:
None
- CZ(qubit_control, qubit_target)¶
- Parameters:
qubit_control (
int
)qubit_target (
int
)
- Return type:
None
- H(qubit_idx)¶
- Parameters:
qubit_idx (
int
)- Return type:
None
- M(qubit_idx)¶
- Parameters:
qubit_idx (
int
)- Return type:
None
- RX(param, qubit_idx)¶
- Parameters:
param (
float
|str
)qubit_idx (
int
)
- Return type:
None
- RXY(phi, theta, qubit_idx)¶
- Parameters:
phi (
float
|str
)theta (
float
|str
)qubit_idx (
int
)
- Return type:
None
- RY(param, qubit_idx)¶
- Parameters:
param (
float
|str
)qubit_idx (
int
)
- Return type:
None
- RZ(param, qubit_idx)¶
- Parameters:
param (
float
|str
)qubit_idx (
int
)
- Return type:
None
- S(qubit_idx)¶
- Parameters:
qubit_idx (
int
)- Return type:
None
- SD(qubit_idx)¶
- Parameters:
qubit_idx (
int
)- Return type:
None
- T(qubit_idx)¶
- Parameters:
qubit_idx (
int
)- Return type:
None
- TD(qubit_idx)¶
- Parameters:
qubit_idx (
int
)- Return type:
None
- X(qubit_idx)¶
- Parameters:
qubit_idx (
int
)- Return type:
None
- X2M(qubit_idx)¶
X rotate -pi/2
- Parameters:
qubit_idx (
int
)- Return type:
None
- X2P(qubit_idx)¶
X rotate pi/2
- Parameters:
qubit_idx (
int
)- Return type:
None
- Y(qubit_idx)¶
- Parameters:
qubit_idx (
int
)- Return type:
None
- Y2M(qubit_idx)¶
Y rotate -pi/2
- Parameters:
qubit_idx (
int
)- Return type:
None
- Y2P(qubit_idx)¶
Y rotate pi/2
- Parameters:
qubit_idx (
int
)- Return type:
None
- Z(qubit_idx)¶
- Parameters:
qubit_idx (
int
)- Return type:
None
- chain(gate_name, qubit_idx=None)¶
Act on each qubit and the next in turn
- Parameters:
gate_name (
str
)qubit_idx (
Sequence
[int
] |None
)
- Return type:
None
- cnot(qubit_control, qubit_target)¶
- Parameters:
qubit_control (
int
)qubit_target (
int
)
- Return type:
None
- comb(gate_name, qubit_idx=None)¶
combinations of all.
- Parameters:
gate_name (
str
)qubit_idx (
Sequence
[int
] |None
)
- Return type:
None
- cx(qubit_control, qubit_target)¶
- Parameters:
qubit_control (
int
)qubit_target (
int
)
- Return type:
None
- cy(qubit_control, qubit_target)¶
- Parameters:
qubit_control (
int
)qubit_target (
int
)
- Return type:
None
- cz(qubit_control, qubit_target)¶
- Parameters:
qubit_control (
int
)qubit_target (
int
)
- Return type:
None
- h(qubit_idx)¶
- Parameters:
qubit_idx (
int
)- Return type:
None
- m(qubit_idx)¶
- Parameters:
qubit_idx (
int
)- Return type:
None
- measure(**kw)¶
Forward calculation.
- mqbit(*qubit_idx)¶
Specifies the object to be measured.
- Parameters:
qubit_idx (
Sequence
[int
] |int
)- Return type:
None
- param(gate_name, qubit_idx=None, param_name='x', param_idx=None)¶
Quickly build parameterized circuits
- Parameters:
gate_name (
str
)qubit_idx (
Sequence
[int
] |None
)param_name (
str
)param_idx (
Sequence
[int
] |None
)
- Return type:
None
- pauli(gates, format='str')¶
Pauli measurement.
- Parameters:
gates (
str
|tuple
)format (
str
)
- Return type:
None
- pauli_measure(**kw)¶
Pauli measurement.
- Return type:
Any
- perm(gate_name, qubit_idx=None)¶
Permutation of all.
- Parameters:
gate_name (
str
)qubit_idx (
Sequence
[int
] |None
)
- Return type:
None
- property qcis: str¶
Join
qcis_list
to get qcis strings.
- ring(gate_name, num_qubits=None)¶
Act on all qubits via a ring
- Parameters:
gate_name (
str
)num_qubits (
int
|None
)
- Return type:
None
- rx(param, qubit_idx)¶
- Parameters:
param (
float
|str
)qubit_idx (
int
)
- Return type:
None
- rxy(phi, theta, qubit_idx)¶
- Parameters:
phi (
float
|str
)theta (
float
|str
)qubit_idx (
int
)
- Return type:
None
- ry(param, qubit_idx)¶
- Parameters:
param (
float
|str
)qubit_idx (
int
)
- Return type:
None
- rz(param, qubit_idx)¶
- Parameters:
param (
float
|str
)qubit_idx (
int
)
- Return type:
None
- s(qubit_idx)¶
- Parameters:
qubit_idx (
int
)- Return type:
None
- sd(qubit_idx)¶
- Parameters:
qubit_idx (
int
)- Return type:
None
- single(gate_name, qubit_idx=None)¶
Act on each qubit in turn
- Parameters:
gate_name (
str
)qubit_idx (
Sequence
[int
] |None
)
- Return type:
None
- t(qubit_idx)¶
- Parameters:
qubit_idx (
int
)- Return type:
None
- td(qubit_idx)¶
- Parameters:
qubit_idx (
int
)- Return type:
None
- x(qubit_idx)¶
- Parameters:
qubit_idx (
int
)- Return type:
None
- x2m(qubit_idx)¶
X rotate -pi/2
- Parameters:
qubit_idx (
int
)- Return type:
None
- x2p(qubit_idx)¶
X rotate pi/2
- Parameters:
qubit_idx (
int
)- Return type:
None
- y(qubit_idx)¶
- Parameters:
qubit_idx (
int
)- Return type:
None
- y2m(qubit_idx)¶
Y rotate -pi/2
- Parameters:
qubit_idx (
int
)- Return type:
None
- y2p(qubit_idx)¶
Y rotate pi/2
- Parameters:
qubit_idx (
int
)- Return type:
None
- z(qubit_idx)¶
- Parameters:
qubit_idx (
int
)- Return type:
None
- exception StrCircuitError¶
Bases:
Exception
Python string quantum circuits error.
Module contents¶
Quantum circuits are at the heart of how quantum computers operate. This package implements tools related to quantum circuits.