QCloudNoiseModel
QCloudNoiseModel represents a noise model for cloud-based quantum simulations. It encapsulates the noise type and its associated parameters for single-qubit and two-qubit gates.
Signature
QCloudNoiseModel()
QCloudNoiseModel(NOISE_MODEL, list[float], list[float])Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
| model | NOISE_MODEL | required | The noise model type |
| single_p | list[float] | required | Single-qubit gate noise parameters |
| double_p | list[float] | required | Two-qubit gate noise parameters |
The default constructor creates a disabled noise model (no noise applied).
NOTE
Positional-only constructor
The three-parameter constructor is positional-only -- keyword arguments are not accepted. Arguments must be passed in order without using parameter names:
# Correct: positional arguments only
QCloudNoiseModel(NOISE_MODEL.DEPOLARIZING_KRAUS_OPERATOR, [0.001], [0.01])
# Incorrect -- raises TypeError:
QCloudNoiseModel(model=NOISE_MODEL.DEPOLARIZING_KRAUS_OPERATOR, single_p=[0.001], double_p=[0.01])Parameter Guidelines
The recommended parameter sizes for each noise model type:
| Model | single_p size | double_p size |
|---|---|---|
DECOHERENCE_KRAUS_OPERATOR | 3 | 3 |
| All other models | 1 | 1 |
For DECOHERENCE_KRAUS_OPERATOR, the three parameters typically represent T1 relaxation time, T2 dephasing time, and gate time. Client-side validation is not enforced at construction time; the server may reject invalid configurations.
Methods
get_noise_model
get_noise_model() -> strReturns the noise model type as a string.
Returns: The noise model name string.
get_single_params
get_single_params() -> list[float]Returns the single-qubit gate noise parameters.
Returns: A list of floating-point noise parameters for single-qubit gates.
set_single_params
set_single_params(single: list[float]) -> NoneSets the single-qubit gate noise parameters.
| Parameter | Type | Description |
|---|---|---|
| single | list[float] | The single-qubit noise parameters |
get_double_params
get_double_params() -> list[float]Returns the two-qubit gate noise parameters.
Returns: A list of floating-point noise parameters for two-qubit gates.
set_double_params
set_double_params(double_p: list[float]) -> NoneSets the two-qubit gate noise parameters.
| Parameter | Type | Description |
|---|---|---|
| double_p | list[float] | The two-qubit noise parameters |
is_enabled
is_enabled() -> boolChecks whether the noise model is enabled (i.e., has been configured with non-empty single-qubit and double-qubit parameter lists).
Returns: True if both the single-qubit and double-qubit parameter lists are non-empty, False otherwise.
print
print() -> NonePrints the noise model type and its parameters to standard output.
Operators
| Operator | Description |
|---|---|
== | Compares two QCloudNoiseModel objects for equality |
!= | Compares two QCloudNoiseModel objects for inequality |
Examples
from pyqpanda3.qcloud import QCloudNoiseModel, NOISE_MODEL, QCloudService
from pyqpanda3.core import QProg, QCircuit, H, CNOT, measure
# Create a default (disabled) noise model
no_noise = QCloudNoiseModel()
print("Enabled:", no_noise.is_enabled()) # False
# Create a depolarizing noise model (positional args only)
noise = QCloudNoiseModel(
NOISE_MODEL.DEPOLARIZING_KRAUS_OPERATOR,
[0.001], # Single-qubit depolarizing probability
[0.01] # Two-qubit depolarizing probability
)
print("Enabled:", noise.is_enabled()) # True
print("Model:", noise.get_noise_model()) # DEPOLARIZING_KRAUS_OPERATOR
# Use the noise model with a backend
# Note: QCloudNoiseModel is currently supported only on the full_amplitude
# simulator backend. Real-chip backends (e.g., WK_C180_2) do not accept
# the noise_model parameter in backend.run().
service = QCloudService(api_key="your_api_key")
backend = service.backend("full_amplitude")
prog = QProg()
circ = QCircuit(2)
circ << H(0) << CNOT(0, 1)
prog << circ << measure([0, 1], [0, 1])
job = backend.run(prog, shots=1000, model=noise)
result = job.result()
print(result.get_probs())
# Modify noise parameters
noise.set_single_params([0.002])
noise.set_double_params([0.02])
noise.print()
# Output:
# Noise Model: DEPOLARIZING_KRAUS_OPERATOR
# Single Qubit Noise Parameters: 0.002
# Double Qubit Noise Parameters: 0.02See Also
- NOISE_MODEL -- Available noise model types
- QCloudService -- Cloud service and backend for running with noise