Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
memory = cirq.GridQubit(register_size+1, 0)
c = cirq.Circuit()
hs = HamiltonianSimulation(A, t)
pe = PhaseEstimation(register_size+1, hs)
c.append([gate(memory) for gate in input_prep_gates])
c.append([
pe(*(register + [memory])),
EigenRotation(register_size+1, C, t)(*(register+[ancilla])),
pe(*(register + [memory]))**-1,
cirq.measure(ancilla)
])
# Pauli observable display
c.append([
cirq.approx_pauli_string_expectation(cirq.Z(ancilla),
num_samples=5000,
key='a'),
cirq.approx_pauli_string_expectation(cirq.X(memory),
num_samples=5000,
key='x'),
cirq.approx_pauli_string_expectation(cirq.Y(memory),
num_samples=5000,
key='y'),
cirq.approx_pauli_string_expectation(cirq.Z(memory),
num_samples=5000,
key='z'),
])
return c
""""Runs the simulator."""
circuit = cirq.Circuit(device=test_device)
for _ in range(num_gates):
which = np.random.choice(['expz', 'expw', 'exp11'])
if which == 'expw':
q1 = cirq.GridQubit(0, np.random.randint(num_qubits))
circuit.append(
cirq.PhasedXPowGate(
phase_exponent=np.random.random(),
exponent=np.random.random()
).on(q1))
elif which == 'expz':
q1 = cirq.GridQubit(0, np.random.randint(num_qubits))
circuit.append(
cirq.Z(q1)**np.random.random())
elif which == 'exp11':
q1 = cirq.GridQubit(0, np.random.randint(num_qubits - 1))
q2 = cirq.GridQubit(0, q1.col + 1)
circuit.append(cirq.CZ(q1, q2)**np.random.random())
circuit.append([
cirq.measure(cirq.GridQubit(0, np.random.randint(num_qubits)),
key='meas')
])
if sim_type == _UNITARY:
circuit.final_wavefunction(initial_state=0)
elif sim_type == _DENSITY:
cirq.DensityMatrixSimulator().run(circuit)
def _decompose_(self, qubits):
a, b = qubits
yield cirq.Z(a) ** -0.5
yield XXYY(a, b) ** self.exponent
yield cirq.Z(a) ** 0.5
def _ops_from_givens_rotations_circuit_description(
qubits: Sequence[cirq.Qid],
circuit_description: Iterable[Iterable[
Union[str, Tuple[int, int, float, float]]]]) -> cirq.OP_TREE:
"""Yield operations from a Givens rotations circuit obtained from
OpenFermion.
"""
for parallel_ops in circuit_description:
for op in parallel_ops:
if op == 'pht':
yield cirq.X(qubits[-1])
else:
i, j, theta, phi = cast(Tuple[int, int, float, float], op)
yield Ryxxy(theta).on(qubits[i], qubits[j])
yield cirq.Z(qubits[j]) ** (phi / numpy.pi)
def fswap(p, q):
"""Decompose the Fermionic SWAP gate into two single-qubit gates and
one iSWAP gate.
Args:
p: the id of the first qubit
q: the id of the second qubit
"""
yield cirq.ISWAP(q, p), cirq.Z(p) ** 1.5
yield cirq.Z(q) ** 1.5
T: cirq.T,
H: cirq.H,
CNOT: cirq.CNOT,
CZ: cirq.CZ,
SWAP: cirq.SWAP,
ISWAP: cirq.ISWAP,
CCZ: cirq.CCZ,
CCNOT: cirq.CCX,
CSWAP: cirq.CSWAP,
}
# TODO: TH -> cirq.ops.HPowGate,
turn_gates = {
TX: cirq.X,
TY: cirq.Y,
TZ: cirq.Z,
XX: cirq.XX,
YY: cirq.YY,
ZZ: cirq.ZZ,
}
for op in circ:
qbs = [qubit_map[qb] for qb in op.qubits]
if type(op) in operations:
cqc.append(operations[type(op)].on(*qbs))
elif type(op) in turn_gates:
t = op.params['t']
cqc.append(turn_gates[type(op)](*qbs) ** t)
elif isinstance(op, IDEN):
gate = cirq.IdentityGate(op.qubit_nb).on(*qbs)
cqc.append(gate)
[0 1/√2 -1/√2 0],
[0 0 0 -1]
The square root of the iSWAP gate is:
[1, 0, 0, 0],
[0, 0.5 + 0.5j, 0.5 - 0.5j, 0],
[0, 0.5 - 0.5j, 0.5 + 0.5j, 0],
[0, 0, 0, 1]
Args:
p: the first qubit
q: the second qubit
"""
yield cirq.Z(p)**1.5
yield cirq.ISWAP(q, p)**0.5
yield cirq.Z(p)**1.5