Skip to content

reformat_parameters() method enables initial_state in list format #700

@JoelPasvolsky

Description

@JoelPasvolsky

The StructuredSolver's reformat_parameters() method states that it "allows initial_state to be submitted as a dictionary mapping the qubits to their initial value" but due to this line

parameters['initial_state'] = {u: state[v]
                                           for v, chain in embedding.items()
                                           for u in chain}

when using an embedding composite (e.g., FixedEmbeddingComposite) you can set initial_state as any list.

sampleset = sampler.sample_ising({}, {(0,1): -1}, 
    anneal_schedule=[[0.0, 1.0], [0.1, 0.95], [0.2, 0.95], [0.3, 1.0]],
    reinitialize_state=True, 
    initial_state=[13, 32], 
    label="test initial 1", 
    num_reads=500)

This would be rejected were you to directly submit such a thing to the QPU:

>>> sampleset = qpu.sample_ising({}, {(0,1): -1}, anneal_schedule=[[0.0, 1.0], ...
SolverFailureError: Invalid length of initial_state

I'm not sure what the preferred behavior is but our documentation states "Specifies the initial classical state of all qubits. ... Provide (qubit, state) pairs..." so we should update the docs to what we want to enable and prevent initial states such as the above (initial_state=[13, 32]) from working.

The context is my finding the structure below being used and not understanding why it was working at first:

initial_state = ((1)**np.arange(N))

where N is the number of qubits in a ferromagnetic ring and `FixedEmbeddingComposite`` is used.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions