circuit#
Photonic quantum circuit
Classes
|
Photonic quantum circuit for a distributed Fock state. |
|
Photonic quantum circuit. |
- class DistributedQumodeCircuit(nmode: int, init_state: Any, cutoff: int | None = None, name: str | None = None)[source]#
Bases:
QumodeCircuitPhotonic quantum circuit for a distributed Fock state.
- Parameters:
nmode (int) – The number of modes in the circuit.
init_state (Any) – The initial state of the circuit. It can be a vacuum state with
'vac'or'zeros'. It can be a Fock basis state, e.g.,[1,0,0], or a Fock state tensor, e.g.,[(1/2**0.5, [1,0]), (1/2**0.5, [0,1])].cutoff (int | None) – The Fock space truncation. Default:
Nonename (str | None) – The name of the circuit. Default:
None
- forward(data: Tensor | None = None, state: DistributedFockState | None = None) DistributedFockState[source]#
Perform a forward pass of the photonic quantum circuit and return the final state.
This method applies the
operatorsof the photonic quantum circuit to the initial state or the given state and returns the resulting state. Ifdatais given, it is used as the input for theencoders. Thedatamust be a 1D tensor.- Parameters:
data (Tensor | None) – The input data for the
encoders. Default:Nonestate (DistributedFockState | None) – The initial state for the photonic quantum circuit. Default:
None
- measure(shots: int = 1024, with_prob: bool = False, wires: int | list[int] | None = None, block_size: int = 16777216) dict | None[source]#
Measure the final state.
- Parameters:
shots (int) – The number of times to sample from the quantum state. Default: 1024
with_prob (bool) – A flag that indicates whether to return the probabilities along with the number of occurrences. Default:
Falsewires (int | list[int] | None) – The wires to measure. It can be an integer or a list of integers specifying the indices of the wires. Default:
None(which means all wires are measured)block_size (int) – The block size for sampling. Default: 2**24
- class QumodeCircuit(nmode: int, init_state: Any, cutoff: int | None = None, backend: str = 'fock', basis: bool = True, den_mat: bool = False, detector: str = 'pnrd', name: str | None = None, mps: bool = False, chi: int | None = None, noise: bool = False, mu: float = 0, sigma: float = 0.1)[source]#
Bases:
OperationPhotonic quantum circuit.
- Parameters:
nmode (int) – The number of modes in the circuit.
init_state (Any) – The initial state of the circuit. It can be a vacuum state with
'vac'or'zeros'. For Fock backend, it can be a Fock basis state, e.g.,[1,0,0], or a Fock state tensor, e.g.,[(1/2**0.5, [1,0]), (1/2**0.5, [0,1])]. Alternatively, it can be a tensor representation. For Gaussian backend, it can be arbitrary Gaussian states with[cov, mean]. For Bosonic backend, it can be arbitrary linear combinations of Gaussian states with[cov, mean, weight], or a list of local Bosonic states. Usexxppconvention and \(\hbar=2\) by default.cutoff (int | None) – The Fock space truncation. Default:
Nonebackend (str) – Use
'fock'for Fock backend,'gaussian'for Gaussian backend or'bosonic'for Bosonic backend. Default:'fock'basis (bool) – Whether to use the representation of Fock basis state for the initial state. Default:
Trueden_mat (bool) – Whether to use density matrix representation. Only valid for Fock state tensor. Default:
Falsedetector (str) – For Gaussian backend, use
'pnrd'for the photon-number-resolving detector or'threshold'for the threshold detector. Default:'pnrd'name (str | None) – The name of the circuit. Default:
Nonemps (bool) – Whether to use matrix product state representation. Default:
Falsechi (int | None) – The bond dimension for matrix product state representation. Default:
Nonenoise (bool) – Whether to introduce Gaussian noise. Default:
Falsemu (float) – The mean of Gaussian noise. Default: 0
sigma (float) – The standard deviation of Gaussian noise. Default: 0.1
- add(op: Operation, encode: bool = False, wires: int | list[int] | None = None) None[source]#
A method that adds an operation to the photonic quantum circuit.
The operation can be a gate or another photonic quantum circuit. The method also updates the attributes of the photonic quantum circuit. If
wiresis specified, the parameters of gates are shared.- Parameters:
op (Operation) – The operation to add. It is an instance of
Operationclass or its subclasses, such asGate, orQumodeCircuit.encode (bool) – Whether the gate is to encode data. Default:
Falsewires (int | list[int] | None) – The wires to apply the gate on. It can be an integer or a list of integers specifying the indices of the wires. Default:
None(which means the gate has its own wires)
- Raises:
AssertionError – If the input arguments are invalid or incompatible with the quantum circuit.
- any(unitary: Any, wires: int | list[int] | None = None, minmax: list[int] | None = None, name: str = 'uany') None[source]#
Add an arbitrary unitary gate.
- bs(wires: list[int], inputs: Any = None, encode: bool = False, mu: float | None = None, sigma: float | None = None) None[source]#
Add a beam splitter.
- bs_h(wires: list[int], inputs: Any = None, encode: bool = False, mu: float | None = None, sigma: float | None = None) None[source]#
Add an H-type beam splitter.
- bs_phi(wires: list[int], inputs: Any = None, encode: bool = False, mu: float | None = None, sigma: float | None = None) None[source]#
Add a beam splitter with fixed \(\theta\) at \(\pi/4\).
- bs_rx(wires: list[int], inputs: Any = None, encode: bool = False, mu: float | None = None, sigma: float | None = None) None[source]#
Add an Rx-type beam splitter.
- bs_ry(wires: list[int], inputs: Any = None, encode: bool = False, mu: float | None = None, sigma: float | None = None) None[source]#
Add an Ry-type beam splitter.
- bs_theta(wires: list[int], inputs: Any = None, encode: bool = False, mu: float | None = None, sigma: float | None = None) None[source]#
Add a beam splitter with fixed \(\phi\) at \(\pi/2\).
- cat(wires: int, r: Any = None, theta: Any = None, p: int = 1) None[source]#
Prepare a cat state.
randthetaare the displacement magnitude and angle respectively.pis the parity, corresponding to an even or odd cat state whenp=0orp=1respectively.
- ck(wires: list[int], inputs: Any = None, encode: bool = False, mu: float | None = None, sigma: float | None = None) None[source]#
Add a cross-Kerr gate.
- clements(unitary: Any, wires: int | list[int] | None = None, minmax: list[int] | None = None, mu: float | None = None, sigma: float | None = None) None[source]#
Add the Clements architecture of the unitary matrix.
This is equivalent to
any, using ‘cssr’-type Clements decomposition. WhenbasisisFalse, this implementation is much faster.
- cp(wires: int, inputs: Any = None, encode: bool = False, mu: float | None = None, sigma: float | None = None) None[source]#
Add a cubic phase gate.
- cx(wires: list[int], inputs: Any = None, encode: bool = False, mu: float | None = None, sigma: float | None = None) None[source]#
Add a controlled-X gate.
- cz(wires: list[int], inputs: Any = None, encode: bool = False, mu: float | None = None, sigma: float | None = None) None[source]#
Add a controlled-Z gate.
- d(wires: int, r: Any = None, theta: Any = None, encode: bool = False, mu: float | None = None, sigma: float | None = None) None[source]#
Add a displacement gate.
- dc(wires: list[int], mu: float | None = None, sigma: float | None = None) None[source]#
Add a directional coupler.
- delay(wires: int, ntau: int = 1, inputs: Any = None, convention: str = 'bs', encode: bool = False, loop_gates: list | None = None, mu: float | None = None, sigma: float | None = None) None[source]#
Add a delay loop.
- draw(filename: str | None = None, unroll: bool = False)[source]#
Visualize the photonic quantum circuit.
- Parameters:
filename (str | None) – The path for saving the figure.
unroll (bool) – Whether to draw the unrolled circuit.
- encode(data: Tensor | None) None[source]#
Encode the input data into the photonic quantum circuit parameters.
This method iterates over the
encodersof the circuit and initializes their parameters with the input data.- Parameters:
data (Tensor | None) – The input data for the
encoders, must be a 1D tensor.
- f(wires: int, mu: float | None = None, sigma: float | None = None) None[source]#
Add a Fourier gate.
- forward(data: Tensor | None = None, state: Any = None, is_prob: bool | None = None, detector: str | None = None, sort: bool = True, stepwise: bool = False) Tensor | dict | list[Tensor][source]#
Perform a forward pass of the photonic quantum circuit and return the final-state-related result.
- Parameters:
data (Tensor | None) – The input data for the
encoders. Default:Nonestate (Any) – The initial state for the photonic quantum circuit. Default:
Noneis_prob (bool | None) – For Fock backend, whether to return probabilities or amplitudes. For Gaussian (Bosonic) backend, whether to return probabilities or the final Gaussian (Bosonic) state. For Fock backend with
basis=True, setNoneto return the unitary matrix. Default:Nonedetector (str | None) – For Gaussian backend, use
'pnrd'for the photon-number-resolving detector or'threshold'for the threshold detector. Default:Nonesort (bool) – Whether to sort dictionary of Fock basis states in the descending order of probabilities. Default:
Truestepwise (bool) – Whether to use the forward function of each operator for Gaussian backend. Default:
False
- Returns:
The result of the photonic quantum circuit after applying the
operators.- Return type:
Tensor | dict | list[Tensor]
- get_amplitude(final_state: Any, init_state: Any = None, unitary: Tensor | None = None) Tensor[source]#
Get the transfer amplitude between the final state and the initial state.
Note
When states are expanded due to photon loss or batched initial states, the amplitudes of the reduced states can not be added, please try
get_probinstead.- Parameters:
final_state (Any) – The final Fock basis state.
init_state (Any) – The initial Fock basis state. Default:
Noneunitary (Tensor | None) – The unitary matrix. Default:
None
- get_displacement(init_mean: Any) Tensor[source]#
Get the final mean value of the Gaussian state in
xxpporder.
- get_fock_basis() Tensor[source]#
Get the output Fock basis states according to the current settings.
- get_prob(final_state: Any, refer_state: Any = None, unitary: Tensor | None = None) Tensor[source]#
Get the probability of the final state related to the reference state.
- Parameters:
final_state (Any) – The final Fock basis state.
refer_state (Any) – The initial Fock basis state or the final Gaussian state. Default:
Noneunitary (Tensor | None) – The unitary matrix. Default:
None
- gkp(wires: int, theta: Any = None, phi: Any = None, amp_cutoff: float = 0.1, epsilon: float = 0.05) None[source]#
Prepare a GKP state.
thetaandphiare angles in Bloch sphere.amp_cutoffis the amplitude threshold for keeping the terms.epsilonis the finite energy damping parameter.
- global_circuit(nstep: int, use_deepcopy: bool = False) QumodeCircuit[source]#
Get the global circuit given the number of time steps.
Note
The initial state of the global circuit is always the vacuum state.
- h(wires: list[int], mu: float | None = None, sigma: float | None = None) None[source]#
Add a photonic Hadamard gate.
- homodyne(wires: int, phi: Any = None, eps: float = 0.0002, mu: float | None = None, sigma: float | None = None) None[source]#
Add a homodyne measurement.
- homodyne_p(wires: int, eps: float = 0.0002, mu: float | None = None, sigma: float | None = None) None[source]#
Add a homodyne measurement for quadrature p.
- homodyne_x(wires: int, eps: float = 0.0002, mu: float | None = None, sigma: float | None = None) None[source]#
Add a homodyne measurement for quadrature x.
- k(wires: int, inputs: Any = None, encode: bool = False, mu: float | None = None, sigma: float | None = None) None[source]#
Add a Kerr gate.
- loss(wires: int, inputs: Any = None, encode: bool = False) None[source]#
Add a photon loss channel.
The inputs corresponds to theta of the loss channel.
- loss_db(wires: int, inputs: Any = None, encode: bool = False) None[source]#
Add a photon loss channel.
The inputs corresponds to the probability of loss with the unit of dB and is positive.
- loss_t(wires: int, inputs: Any = None, encode: bool = False) None[source]#
Add a photon loss channel.
The inputs corresponds to the transmittance of the loss channel.
- property max_depth: int#
Get the max number of gates on the wires.
- measure(shots: int = 1024, with_prob: bool = False, wires: int | list[int] | None = None, detector: str | None = None, mcmc: bool = False) dict | list[dict] | None[source]#
Measure the final state.
- Parameters:
shots (int) – The number of times to sample from the quantum state. Default: 1024
with_prob (bool) – A flag that indicates whether to return the probabilities along with the number of occurrences. Default:
Falsewires (int | list[int] | None) – The wires to measure. It can be an integer or a list of integers specifying the indices of the wires. Default:
None(which means all wires are measured)detector (str | None) – For Gaussian backend, use
'pnrd'for the photon-number-resolving detector or'threshold'for the threshold detector. Default:Nonemcmc (bool) – Whether to use MCMC sampling method. Default:
False
See https://arxiv.org/pdf/2108.01622 for MCMC.
- measure_homodyne(shots: int = 10, wires: int | list[int] | None = None) Tensor | None[source]#
Get the homodyne measurement results.
If
self.measurementsis specified viaself.homodyne, return the results of the conditional homodyne measurement. Otherwise, return the results of the ideal homodyne measurement. The Gaussian states after measurements are stored inself.state_measured.Note
batch*shotscan not be too large for Fock backend.- Parameters:
shots (int) – The number of times to sample from the quantum state. Default: 10
wires (int | list[int] | None) – The wires to measure for the ideal homodyne. It can be an integer or a list of integers specifying the indices of the wires. Default:
None(which means all wires are measured)
- mzi(wires: list[int], inputs: Any = None, phi_first: bool = True, encode: bool = False, mu: float | None = None, sigma: float | None = None) None[source]#
Add a Mach-Zehnder interferometer.
- photon_number_mean_var(wires: int | list[int] | None = None) tuple[Tensor, Tensor] | None[source]#
Get the expectation value and variance of the photon number operator.
- Parameters:
wires (int | list[int] | None) – The wires to measure. It can be an integer or a list of integers specifying the indices of the wires. Default:
None(which means all wires are measured)
- ps(wires: int, inputs: Any = None, encode: bool = False, mu: float | None = None, sigma: float | None = None) None[source]#
Add a phase shifter.
- qp(wires: int, inputs: Any = None, encode: bool = False, mu: float | None = None, sigma: float | None = None) None[source]#
Add a quadratic phase gate.
- quadrature_mean(wires: int | list[int] | None = None, phi: Any | None = None) Tensor[source]#
Get the expectation value of the quadratuere operator \(\hat{X}\cos\phi + \hat{P}\sin\phi\).
If
self.measurementsis empty, this method directly computes the quadrature expectation values for the specifiedwiresandphi. Ifself.measurementsis specified viaself.homodyne, the wires and corresponding homodyne angles are inferred from the stored measurement instructions, and the input argumentswiresandphiare ignored.- Parameters:
wires (int | list[int] | None) – The wires to measure. It can be an integer or a list of integers specifying the indices of the wires. Default:
None(which means all wires are measured).phi (Any | None) – The phi angles for quadrature operator \(\hat{X}\cos\phi + \hat{P}\sin\phi\). Default:
None
- r(wires: int, inputs: Any = None, encode: bool = False, inv_mode: bool = False, mu: float | None = None, sigma: float | None = None) None[source]#
Add a rotation gate.
- s(wires: int, r: Any = None, theta: Any = None, encode: bool = False, mu: float | None = None, sigma: float | None = None) None[source]#
Add a squeezing gate.
- s2(wires: list[int], r: Any = None, theta: Any = None, encode: bool = False, mu: float | None = None, sigma: float | None = None) None[source]#
Add a two-mode squeezing gate.
- set_fock_basis(state: Any = None, reset_in_forward: bool = False) None[source]#
Set the output Fock basis states.
By default it will generate all Fock basis states according to the inital state.
- Parameters:
state (Any) – The output Fock basis states. Default:
Nonereset_in_forward (bool) – Whether to recompute the output Fock basis states in the forward pass. Default:
False