Simulator#

class Simulator(d: int, config: Optional[piquasso.api.config.Config] = None)#

Base class for all simulators defined in Piquasso.

create_initial_state()#

Creates an initial state with no instructions executed.

Note: This not necessarily needs to be a vacuum state.

Returns

The initial state of the simulation.

Return type

State

validate(program: piquasso.api.program.Program) None#

Validates the specified program.

Raises
  • InvalidInstruction – When invalid instructions are defined in the program.

  • InvalidSimulation – When the instructions are valid, but the simulator couldn’t execute the specified program.

Parameters

program (Program) – The program to validate.

execute_instructions(instructions: List[piquasso.api.instruction.Instruction], initial_state: Optional[piquasso.api.state.State] = None, shots: int = 1) piquasso.api.result.Result#

Executes the specified instruction list.

Parameters
  • instructions (List[Instruction]) – The instructions to execute.

  • initial_state (State, optional) – A state to execute the instructions on. Defaults to the state created by create_initial_state().

  • shots (int, optional) – The number of times the program should be execute. Defaults to 1.

Raises

InvalidParameter – When shots is not a positive integer.

Returns

The result of the simulation containing the resulting state and samples if any measurement is specified in instructions.

Return type

Result

execute(program: piquasso.api.program.Program, shots: int = 1, initial_state: Optional[piquasso.api.state.State] = None) piquasso.api.result.Result#

Executes the specified program.

Parameters
  • program (Program) – The program to execute.

  • initial_state (State, optional) – A state to execute the instructions on. Defaults to the state created by create_initial_state().

  • shots (int, optional) – The number of times the program should execute. Defaults to 1.

Raises

InvalidParameter – When shots is not a positive integer.

Returns

The result of the simulation containing the resulting state and samples if any measurement is specified in program.

Return type

Result