mimiqcircuits.addnoise¶
Functions
|
Return a copy of |
|
Add |
|
Return a decorated copy, decorating one by one or by blocks. |
|
Decorate matching instructions in place, one by one or by blocks. |
|
Return a copy of |
|
Add generated instructions next to blocks of parallel matches, in place. |
|
Return a decorated copy of |
|
Add generated instructions next to every matching instruction, in place. |
- decorate_on_match_single_inplace(circuit, matcher, generator, before=False)[source]¶
Add generated instructions next to every matching instruction, in place.
For each instruction
instofcircuitwithmatcher(inst)true, the output ofgenerator(inst)is inserted right afterinst(or right before it). The generator returns one of:an
Instruction;a tuple
(operation, targets), such as(noise, inst.qubits), or(operation, qubits, bits, zvars);a tuple
(circuit,), whose instructions are inserted as they are.
This is the engine behind
Circuit.decorate_on_match_single().- Parameters:
circuit (Circuit) – Circuit to change.
matcher (Callable[[Instruction], bool]) – Function
inst -> boolselecting the instructions.generator (Callable[[Instruction], Any]) – Function
inst -> instruction or tuplegiving what to insert.before (bool) – Insert before each match instead of after it.
- Returns:
circuititself, changed.- Return type:
- Raises:
TypeError – If the generator returns an unsupported value.
Examples
>>> from mimiqcircuits import * >>> from mimiqcircuits.addnoise import decorate_on_match_single_inplace >>> c = Circuit() >>> _ = c.push(GateH(), 0) >>> _ = c.push(GateCX(), 0, 1) >>> # add bit-flip noise after every one-qubit gate >>> decorate_on_match_single_inplace( ... c, ... lambda inst: inst.operation.num_qubits == 1, ... lambda inst: (PauliX(0.01), inst.qubits), ... ) 2-qubit circuit with 3 instructions: ├── H @ q[0] ├── PauliX(0.01) @ q[0] └── CX @ q[0], q[1]
- decorate_on_match_single(circuit, matcher, generator, before=False)[source]¶
Return a decorated copy of
circuit.Same as
decorate_on_match_single_inplace(), applied to a deep copy;circuitis not changed.- Returns:
The decorated copy.
- Return type:
- decorate_on_match_parallel_inplace(circuit, matcher, generator, before=False)[source]¶
Add generated instructions next to blocks of parallel matches, in place.
A block is a run of consecutive matching instructions that act on disjoint qubits, bits and z-variables, such as the instructions produced by one broadcast
Circuit.push(). The generated instructions of a whole block are inserted together, after the block (or before it). Thematcherandgeneratorfollow the same rules as indecorate_on_match_single_inplace().This is the engine behind
Circuit.decorate_on_match_parallel().- Parameters:
circuit (Circuit) – Circuit to change.
matcher (Callable[[Instruction], bool]) – Function
inst -> boolselecting the instructions.generator (Callable[[Instruction], Any]) – Function
inst -> instruction or tuplegiving what to insert.before (bool) – Insert before each block instead of after it.
- Returns:
circuititself, changed.- Return type:
- Raises:
TypeError – If the generator returns an unsupported value.
Examples
>>> from mimiqcircuits import * >>> from mimiqcircuits.addnoise import decorate_on_match_parallel_inplace >>> c = Circuit() >>> _ = c.push(GateH(), range(3)) >>> # the three H gates form one block: the noise comes after all of them >>> decorate_on_match_parallel_inplace( ... c, ... lambda inst: inst.operation == GateH(), ... lambda inst: (AmplitudeDamping(0.1), inst.qubits), ... ) 3-qubit circuit with 6 instructions: ├── H @ q[0] ├── H @ q[1] ├── H @ q[2] ├── AmplitudeDamping(0.1) @ q[0] ├── AmplitudeDamping(0.1) @ q[1] └── AmplitudeDamping(0.1) @ q[2]
- decorate_on_match_parallel(circuit, matcher, generator, *, before=False)[source]¶
Return a copy of
circuitdecorated block by block.Same as
decorate_on_match_parallel_inplace(), applied to a deep copy;circuitis not changed.beforeis keyword-only.- Returns:
The decorated copy.
- Return type:
- decorate_inplace(circuit, matcher, generator, before=False, parallel=False)[source]¶
Decorate matching instructions in place, one by one or by blocks.
Calls
decorate_on_match_parallel_inplace()whenparallelisTrueanddecorate_on_match_single_inplace()otherwise.- Returns:
circuititself, changed.- Return type:
- decorate(circuit, matcher, generator, *, before=False, parallel=False)[source]¶
Return a decorated copy, decorating one by one or by blocks.
Calls
decorate_on_match_parallel()whenparallelisTrueanddecorate_on_match_single()otherwise.circuitis not changed.- Returns:
The decorated copy.
- Return type:
- add_noise_inplace(circuit, g, noise, before=False, parallel=False)[source]¶
Add
noisenext to every instance ofg, in place.noiseacts on the same qubits as each matched instruction, so it must act on as many qubits asg. This is the engine behindCircuit.add_noise().- Parameters:
circuit (Circuit) – Circuit to change.
g (Operation | type) – Operation to match. An instance matches equal operations; an
Operationsubclass, such asGateH, matches all its instances.noise (krauschannel | Gate) – Gate or Kraus channel to add.
before (bool) – Add the noise before each match instead of after it.
parallel (bool) – Add the noise after (or before) each block of parallel matches, as in
decorate_on_match_parallel_inplace().
- Returns:
circuititself, changed.- Return type:
- Raises:
TypeError – If
noiseis not a gate or Kraus channel, orgis neither an operation nor an operation class.ValueError – If
noiseacts on a different number of qubits than a matched instruction.
Examples
>>> from mimiqcircuits import * >>> from mimiqcircuits.addnoise import add_noise_inplace >>> c = Circuit() >>> _ = c.push(GateH(), 0) >>> _ = c.push(GateX(), 1) >>> # match every Pauli X gate by its class >>> add_noise_inplace(c, GateX, PauliZ(0.05)) 2-qubit circuit with 3 instructions: ├── H @ q[0] ├── X @ q[1] └── PauliZ(0.05) @ q[1]
- add_noise(circuit, g, noise, before=False, parallel=False)[source]¶
Return a copy of
circuitwithnoiseadded next to everyg.Same as
add_noise_inplace(), applied to a deep copy;circuitis not changed.- Returns:
The noisy copy.
- Return type: