Skip to content

Commit ba7de48

Browse files
committed
Change order of arguments to be consistent across different quantum modules
1 parent 3b8ee4b commit ba7de48

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

examples/cuquantum/qaoa.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ def __init__(self, n_wires, input_graph, n_layers):
5050
hamiltonian[pauli_string] = 0.5
5151

5252
backend = CuTensorNetworkBackend(TNConfig(num_hyper_samples=10))
53-
self.energy = QuantumExpectation(self.circuit, [hamiltonian], backend)
54-
self.sampling = QuantumSampling(self.circuit, 100, backend)
53+
self.energy = QuantumExpectation(self.circuit, backend, [hamiltonian])
54+
self.sampling = QuantumSampling(self.circuit, backend, 100)
5555

5656
def forward(self):
5757
start_time = torch.cuda.Event(enable_timing=True)

torchquantum/plugin/cuquantum/amplitude.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ class QuantumAmplitude(nn.Module):
1818
1919
Args:
2020
circuit: The quantum circuit that prepares the state.
21-
bitstrings: List of bitstrings whose amplitudes to compute.
2221
backend: The quantum backend to use for computation.
22+
bitstrings: List of bitstrings whose amplitudes to compute.
2323
"""
2424

25-
def __init__(self, circuit: ParameterizedQuantumCircuit, bitstrings: List[str], backend: QuantumBackend):
25+
def __init__(self, circuit: ParameterizedQuantumCircuit, backend: QuantumBackend, bitstrings: List[str]):
2626
super().__init__()
2727
self._circuit = circuit.copy()
2828
self._bitstrings = bitstrings.copy()

torchquantum/plugin/cuquantum/expectation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ class QuantumExpectation(nn.Module):
1919
2020
Args:
2121
circuit: The quantum circuit that prepares the state.
22+
backend: The quantum backend to use for computation.
2223
pauli_ops: List of Pauli operators to compute expectations for. Each Pauli operator can be either:
2324
- A single Pauli string specifying the pauli operator for each qubit ("I", "X", "Y", or "Z").
2425
- A linear combination of Pauli strings specified as a dictionary mapping each single Pauli string to
2526
its corresponding coefficient.
26-
backend: The quantum backend to use for computation.
2727
"""
2828

2929
def __init__(
3030
self,
3131
circuit: ParameterizedQuantumCircuit,
32-
pauli_ops: Union[List[str], Dict[str, float]],
3332
backend: QuantumBackend,
33+
pauli_ops: Union[List[str], Dict[str, float]],
3434
):
3535
super().__init__()
3636
self._circuit = circuit.copy()

torchquantum/plugin/cuquantum/sampling.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,23 @@
1414
class QuantumSampling(nn.Module):
1515
"""A PyTorch module for sampling from quantum states.
1616
17-
This module generates samples from the quantum state prepared by a given quantum circuit. It can sample from all
17+
This module generates samples from the quantum state prepared by a given quantum circuit. It can sample from all
1818
qubits or a specified subset of qubits.
1919
2020
Args:
2121
circuit: The quantum circuit that prepares the state.
22-
n_samples: Number of samples to generate per batch.
2322
backend: The quantum backend to use for computation.
23+
n_samples: Number of samples to generate per batch.
2424
wires: Optional list of wires/qubits to sample from. If not provided, all wires/qubits are sampled from.
2525
"""
26-
27-
def __init__(self, circuit:ParameterizedQuantumCircuit, n_samples: int, backend: QuantumBackend, wires: Optional[List[int]]=None):
26+
27+
def __init__(
28+
self,
29+
circuit: ParameterizedQuantumCircuit,
30+
backend: QuantumBackend,
31+
n_samples: int,
32+
wires: Optional[List[int]] = None,
33+
):
2834
super().__init__()
2935
self.circuit = circuit
3036
self.n_samples = n_samples

0 commit comments

Comments
 (0)