Did I find the right examples for you? yes no      Crawl my project      Python Jobs

# sympy.physics.quantum.identitysearch.is_reducible

All Samples(6)  |  Call(5)  |  Derive(0)  |  Import(1)
```Determines if a circuit is reducible by checking
if its subcircuits are scalar values.

Parameters
==========

circuit : Gate tuple
A tuple of Gates representing a circuit.  The circuit to check
if a gate identity is contained in a subcircuit.
nqubits : int(more...)
```

```        def is_reducible(circuit, nqubits, begin, end):
"""Determines if a circuit is reducible by checking
if its subcircuits are scalar values.

Parameters
==========

circuit : Gate tuple
A tuple of Gates representing a circuit.  The circuit to check
if a gate identity is contained in a subcircuit.
nqubits : int
The number of qubits the circuit operates on.
begin : int
The leftmost gate in the circuit to include in a subcircuit.
end : int
The rightmost gate in the circuit to include in a subcircuit.

Examples
========

Check if the circuit can be reduced:

>>> from sympy.physics.quantum.identitysearch import (
...     GateIdentity, is_reducible)
>>> from sympy.physics.quantum.gate import X, Y, Z
>>> x = X(0); y = Y(0); z = Z(0)
>>> is_reducible((x, y, z), 1, 0, 3)
True

Check if an interval in the circuit can be reduced:

>>> is_reducible((x, y, z), 1, 1, 3)
False

>>> is_reducible((x, y, y), 1, 1, 3)
True
"""

current_circuit = ()
# Start from the gate at "end" and go down to almost the gate at "begin"
for ndx in reversed(range(begin, end)):
next_gate = circuit[ndx]
current_circuit = (next_gate,) + current_circuit

# If a circuit as a matrix is equivalent to a scalar value
if (is_scalar_matrix(current_circuit, nqubits, False)):
return True

return False
```

```from sympy.physics.quantum.gate import (X, Y, Z, H, S, T, CNOT,
IdentityGate, CGate, PhaseGate, TGate, gate_simp)
from sympy.physics.quantum.identitysearch import (generate_gate_rules,
generate_equivalent_ids, GateIdentity, bfs_identity_search,
random_identity_search, is_scalar_sparse_matrix,
```
```
circuit = (x, y, y)
assert is_reducible(circuit, nqubits, 1, 3) is True

circuit = (x, y, x)
assert is_reducible(circuit, nqubits, 1, 3) is False

circuit = (x, y, y, x)
assert is_reducible(circuit, nqubits, 0, 4) is True
```
```
circuit = (x, y, y, x)
assert is_reducible(circuit, nqubits, 1, 3) is True

circuit = (x, y, z, y, y)
```